Spring data ElastiSearch aggregations with filters

前端 未结 1 1251
暖寄归人
暖寄归人 2021-01-01 07:48

I am trying to perform aggregations on values filtered by some conditions. I am using ElasticSearchTemplate.query() method of spring data too execute query and get the resul

相关标签:
1条回答
  • 2021-01-01 08:25

    This behaviour is by design in Elasticsearch.

    In very simple words, input to aggregations AND post filter is the set of documents that match the query section of the request body. Hence aggregations are not applied over the filtered documents.

    However, if you do want aggregations to be applied over the filtered documents, "move the filters inside the query section", that is, use filtered query. Now output of the query section will be the filtered set of documents and aggregations will apply on them as expected.

    So for your requirements, use filtered query instead of post filter.

    0 讨论(0)
提交回复
热议问题