Reputation: 1291
I am querying ElasticSearch using Java API. Now i am able to query aggregation in one field. Its code given below.
SearchResponse res = client.prepareSearch("myindex").addAggregation(AggregationBuilders.terms("aggs").field("item_type"))
.setQuery(QueryBuilders.queryStringQuery("item_name:dell"))
.setSize(10).execute().actionGet();
Here i need to add one more aggregation field along with item_type like brand etc. How do i add more fields along with item_type.How do i do that with java API.
Upvotes: 0
Views: 43
Reputation: 413
Add another aggregation at top level
SearchResponse res = client.prepareSearch("myindex").addAggregation(AggregationBuilders.terms("aggs").field("item_type")).addAggregation(AggregationBuilders.terms("aggs2).field("item_type2))
.setQuery(QueryBuilders.queryStringQuery("item_name:dell"))
.setSize(10).execute().actionGet();
Upvotes: 1