반응형
Recent Posts
Recent Comments
관리 메뉴

개발잡부

[es] nested aggregation 본문

ElasticStack/Elasticsearch

[es] nested aggregation

닉의네임 2022. 7. 16. 18:50
반응형

검색쿼리

GET /products_nested/_search?size=0
{
  "query": {
    "match": {
      "name": "led tv"
    }
  },
  "aggs": {
    "resellers": {
      "nested": {
        "path": "resellers"
      },
      "aggs": {
        "filter_reseller": {
          "filter": {
            "bool": {
              "filter": [
                {
                  "term": {
                    "resellers.reseller": "companyB"
                  }
                }
              ]
            }
          },
          "aggs": {
            "min_price": {
              "min": {
                "field": "resellers.price"
              }
            },
            "resller": {
              "terms": {
                "field": "resellers.reseller",
                "size": 10
              }
            }
          }
        }
      }
    }
  }
}

 

PUT /products_nested
{
  "settings": {
    "index": {
      "number_of_shards": 3,
      "number_of_replicas": 0
    }
  },
  "mappings": {
    "properties": {
      "resellers": {
        "type": "nested",
        "properties": {
          "reseller": {
            "type": "keyword"
          },
          "price": {
            "type": "double"
          }
        }
      }
    }
  }
}
PUT /products_nested/_doc/0?refresh
{
  "name": "LED TV", 
  "resellers": [
    {
      "reseller": "companyA",
      "price": 350
    },
    {
      "reseller": "companyB",
      "price": 500
    }
  ]
}


PUT /products_nested/_doc/1?refresh
{
  "name": "ODIO RADIO", 
  "resellers": [
    {
      "reseller": "companyA",
      "price": 150
    },
    {
      "reseller": "companyC",
      "price": 550
    }
  ]
}

 

반응형

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

[es] aggregation test 3  (0) 2022.07.19
[es] aggregation test 2  (0) 2022.07.17
[es] aggregation test 1  (0) 2022.07.16
[es] Array Aggregations  (0) 2022.07.15
[es] Aggregations  (0) 2022.07.14
Comments