ElasticSearch - how to exclude filter from aggregations?

前端 未结 2 1429
暗喜
暗喜 2021-01-02 12:13

I have filtered query with 3 filters: \"query\": \"iphone\", color:5, category:10, brand:25.

How can I get amount of products in each brand which have <

2条回答
  •  攒了一身酷
    2021-01-02 13:17

    In addition to @Lionel Sengkouvanh answer, here's the equivalent with the java API:

    SearchRequestBuilder request = client
      .prepareSearch(INDEX_NAME)
      .setQuery(theQuery)
      ...
      .addAggregation(
         AggregationBuilders.global("all").subAggregation(      
           AggregationBuilders.filter("keyword").filter(filter).subAggregation(
             AggregationBuilders.terms("brand").field("brand")  
           )
         )
      );
    

提交回复
热议问题