elasticsearch 인기 어휘 전시 실현
2056 단어 elasticsearch
//
SearchRequestBuilder requestBuilder = esClient.prepareSearch("index").setTypes("log").setQuery(QueryBuilders.matchAllQuery());
// 10
SearchResponse actionGet = requestBuilder.addAggregation(AggregationBuilders.terms("hotWord").field("keywords").size(10)).execute().actionGet();
//
Aggregations aggregations = actionGet.getAggregations();
Terms trem = aggregations.get("hotWord");
List buckets = trem.getBuckets();
List hotWords = new ArrayList<>();
for (Bucket bucket : buckets) {
String key = (String) bucket.getKey();
hotWords.add(key);
}