Multiple filters and an aggregate in elasticsearch

前端 未结 4 657
广开言路
广开言路 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:49

    more on @geekQ 's answer: to support filter string with space char,for multipal term search,use below:

    {   "aggs": {
        "aggresults": {
          "filter": {
            "bool": {
              "must": [
                {
                  "match_phrase": {
                    "term_1": "some text with space 1"
                  }
                },
                {
                  "match_phrase": {
                    "term_2": "some text with also space 2"
                  }
                }
              ]
            }
          },
          "aggs" : {
                "all_term_3s" : {
                    "terms" : {
                        "field":"term_3.keyword",
                        "size" : 10000,
                        "order" : {
                            "_term" : "asc" 
                        }
                    }
               }
            }
        }   },   "size": 0 }
    

提交回复
热议问题