Elasticsearch聚合
聚合分词
http://localhost:9200/{index}/{type}/_search
{
"aggs": {
"brands": {
"terms": { "field": "goods.brandKey" }
}
}
}
NativeSearchQuery query = new NativeSearchQueryBuilder() .withIndices("pdm").withTypes("sku") .addAggregation(AggregationBuilders.terms("names").field("name")) .build(); Aggregations list = template.query(query, new ResultsExtractor<Aggregations>() { @Override public Aggregations extract(SearchResponse response) { return response.getAggregations(); } }); for (Aggregation item : list) {
System.out.println(item.getName());
StringTerms terms = (StringTerms)item; for (Bucket bucket : terms.getBuckets()) { System.out.println(bucket.getKeyAsString()); } }