반응형
Recent Posts
Recent Comments
관리 메뉴

개발잡부

[es] bucket aggregations 본문

ElasticStack/Elasticsearch

[es] bucket aggregations

닉의네임 2022. 7. 14. 14:19
반응형

전체 쿼리  

더보기

GET hyper-item,ds-item/_search
{
  "from": 0,
  "size": 0,
  "timeout": "60s",
  "query": {
    "bool": {
      "filter": [
        {
          "range": {
            "saleStartDt": {
              "from": null,
              "to": "now/m",
              "include_lower": true,
              "include_upper": true,
              "boost": 1
            }
          }
        },
        {
          "range": {
            "saleEndDt": {
              "from": "now/m",
              "to": null,
              "include_lower": true,
              "include_upper": true,
              "boost": 1
            }
          }
        },
        {
          "term": {
            "docDispYn": {
              "value": "Y",
              "boost": 1
            }
          }
        },
        {
          "bool": {
            "should": [
              {
                "terms": {
                  "itemStoreInfo.storeId": [
                    "37",
                    "20163"
                  ],
                  "boost": 1
                }
              },
              {
                "term": {
                  "shipMethod": {
                    "value": "TD_DLV",
                    "boost": 1
                  }
                }
              },
              {
                "term": {
                  "storeType": {
                    "value": "DS",
                    "boost": 1
                  }
                }
              }
            ],
            "adjust_pure_negative": true,
            "boost": 1
          }
        },
        {
          "multi_match": {
            "query": "풀무원",
            "fields": [
              "brandNmEng^1.0",
              "brandNmKor^1.0",
              "category.categorySearchKeyword^1.0",
              "category.dcateNm^1.0",
              "isbn^1.0",
              "itemNo^1.0",
              "itemOptionNms^1.0",
              "itemStoreInfo.eventInfo.eventKeyword^1.0",
              "searchItemNm^1.0",
              "searchKeyword^1.0"
            ],
            "type": "cross_fields",
            "operator": "AND",
            "slop": 0,
            "prefix_length": 0,
            "max_expansions": 50,
            "zero_terms_query": "NONE",
            "auto_generate_synonyms_phrase_query": false,
            "fuzzy_transpositions": true,
            "boost": 1
          }
        }
      ],
      "adjust_pure_negative": true,
      "boost": 1
    }
  },
  "aggregations": {
    "LCATE": {
      "terms": {
        "field": "filterInfo.lcate",
        "size": 500,
        "min_doc_count": 1,
        "shard_min_doc_count": 0,
        "show_term_doc_count_error": false,
        "order": [
          {
            "_count": "desc"
          },
          {
            "LCATE_ORDER": "asc"
          },
          {
            "_key": "asc"
          }
        ]
      },
      "aggregations": {
        "LCATE_ORDER": {
          "min": {
            "field": "category.lcatePriority"
          }
        }
      }
    },
    "PARTNER": {
      "terms": {
        "field": "filterInfo.shop",
        "size": 20,
        "min_doc_count": 1,
        "shard_min_doc_count": 0,
        "show_term_doc_count_error": false,
        "order": [
          {
            "_count": "desc"
          },
          {
            "_key": "asc"
          }
        ]
      }
    },
    "BRAND": {
      "terms": {
        "field": "filterInfo.brand",
        "size": 20,
        "min_doc_count": 1,
        "shard_min_doc_count": 0,
        "show_term_doc_count_error": false,
        "order": [
          {
            "_count": "desc"
          },
          {
            "_key": "asc"
          }
        ]
      }
    },
    "MALL_TYPE": {
      "terms": {
        "field": "mallType",
        "size": 20,
        "min_doc_count": 1,
        "shard_min_doc_count": 0,
        "show_term_doc_count_error": false,
        "order": [
          {
            "_count": "desc"
          },
          {
            "_key": "asc"
          }
        ]
      }
    },
    "GRADE": {
      "range": {
        "field": "grade",
        "ranges": [
          {
            "to":1
          },
          {
            "from": 1,
            "to": 2
          },
          {
            "from": 2,
            "to": 3
          },
          {
            "from": 3,
            "to": 4
          },
          {
            "from": 4,
            "to": 5
          },
          {
            "from": 5
          }
        ]
      }
    }
  }
}

 

 
 
aggs 에 설정한 from이상 즉 버킷에 포함이고 to미만 으로 버킷에 포함하지 않습니다. 예를 들어 필드 값이 2 인 도큐먼트는 "key" : "1-2" 버킷에는 포함되지 않고 "key" : "2-3" 버킷에는 포함됩니다.
    "GRADE": {
      "range": {
        "field": "grade",
        "ranges": [
          {
            "to":1
          },
          {
            "from": 1,
            "to": 2
          },
          {
            "from": 2,
            "to": 3
          },
          {
            "from": 3,
            "to": 4
          },
          {
            "from": 4,
            "to": 5
          },
          {
            "from": 5
          }
        ]
      }
    }

결과값

  "GRADE" : {
      "buckets" : [
        {
          "key" : "*-1.0",
          "to" : 1.0,
          "doc_count" : 158
        },
        {
          "key" : "1.0-2.0",
          "from" : 1.0,
          "to" : 2.0,
          "doc_count" : 2
        },
        {
          "key" : "2.0-3.0",
          "from" : 2.0,
          "to" : 3.0,
          "doc_count" : 1
        },
        {
          "key" : "3.0-4.0",
          "from" : 3.0,
          "to" : 4.0,
          "doc_count" : 2
        },
        {
          "key" : "4.0-5.0",
          "from" : 4.0,
          "to" : 5.0,
          "doc_count" : 309
        },
        {
          "key" : "5.0-*",
          "from" : 5.0,
          "doc_count" : 15
        }
      ]
    },

 

반응형

'ElasticStack > Elasticsearch' 카테고리의 다른 글

[es] Array Aggregations  (0) 2022.07.15
[es] Aggregations  (0) 2022.07.14
[es] aggregations script  (0) 2022.07.14
[es] sort - payload sort 2  (0) 2022.07.03
[es] script similarity test phase 2  (0) 2022.07.03
Comments