티스토리 뷰

term : 정확하게 맞는 검색어 질의
match :  검색어 분석후 질의
match_phrase : 검색어 분석후 질의


0.terms(복수개의 term 검색)

{
  "query": {
    "bool": {
      "filter": [
        {
          "bool": {
            "must": [
              {
                "terms": {
                  "tagInfo.tags": [
                    "냉장고"
                  ]
                }
              }
            ]
          }
        }
      ]
    }
  }
}

0-1.terms고 검색한 내용중 userId로 집계(aggregation)

{

  "from": 0,
  "size": 0,
  "query": {
    "bool": {
      "filter": [
        {
          "bool": {
            "must": [
              {
                "terms": {
                  "tagInfo.tags": [
                    "냉장고"
                  ]
                }
              }
            ]
          }
        }
      ]
    }
  },
  "aggs": {
    "group_by_page.hostname": {
      "terms": {
        "field": "userId",
        "order": {
          "_count": "desc"
        }
      }
    }
  }
}

1.info.siteSeq / logType / range로 조회

{
  "query": {
    "bool": {
      "filter": [
        {
          "bool": {
            "must": [
              {
                "term": {
                  "info.siteSeq": {
                    "value": -48,
                    "boost": 1
                  }
                }
              },
              {
                "term": {
                  "logType": {
                    "value": "join",
                    "boost": 1
                  }
                }
              }
            ],
            "adjust_pure_negative": true,
            "boost": 1
          }
        },
        {
          "range": {
            "timestamp": {
              "from": 1555340400000,
              "to": 1555426799000,
              "include_lower": true,
              "include_upper": true,
              "boost": 1
            }
          }
        }
      ],
      "adjust_pure_negative": true,
      "boost": 1
    }
  }
}

2.Custom.og:title으로 키워드 부분 검색

{
  "query": {
    "bool": {
      "should": [
        {
          "match_phrase": {
            "custom.og:title": "롯데홈쇼핑"
          }
        },
        {
          "match_phrase": {
            "custom.og:title": "홈쇼핑"
          }
        }
      ]
    }
  }
}

3. Page.hostname으로 group 후 내리차순으로 상위 3개만 추출

{
  "size": 0,
  "aggs": {
    "group_by_page.hostname": {
      "terms": {
        "field": "page.hostname",
        "size": 3,
        "order": {
          "_count": "desc"
        }
      }
    }
  }
}

# 여러개 컬럼 동시 검색

{
  "size": 1000,
  "sort": {
    "timestamp": "asc"
  },
  "query": {
    "bool": {
      "filter": [
        {
          "bool": {
            "must": [
              {
                "term": {
                  "info.siteSeq": 155056
                }
              },
              {
                "term": {
                  "logType": "purchase"
                }
              }
            ]
          }
        },
        {
          "range": {
            "timestamp": {
              "from": "2019-01-01 09:00",
              "to": "2019-04-30 00:00",
              "format": "yyyy-MM-dd HH:mm",
              "include_lower": "true",
              "include_upper": "true",
              "boost": 1
            }
          }
        }
      ]
    }
  }
}