Multiple filters and an aggregate in elasticsearch

前端 未结 4 654
广开言路
广开言路 2020-12-14 01:26

How can I use a filter in connection with an aggregate in elasticsearch?

The official documentation gives only trivial examples for filter and for aggregations and n

4条回答
  •  感情败类
    2020-12-14 01:57

    Just for reference, as for the version 7.2, I tried with something as follows to achieve multiple filters for aggregation:

    • filter aggregation to filter for aggregation
    • use bool to set up the compound query
    POST movies/_search?size=0
    {
      "size": 0,
      "aggs": {
        "test": {
          "filter": {
            "bool": {
              "must": {
                "term": {
                  "genre": "action"
                }
              },
              "filter": {
                "range": {
                  "year": {
                    "gte": 1800,
                    "lte": 3000
                  }
                }
              }
            }
          },
          "aggs": {
            "year_hist": {
              "histogram": {
                "field": "year",
                "interval": 50
              }
            }
          }
        }
      }
    }
    

提交回复
热议问题