如果用java整合es实现词频统计?
我目前的实现方案:
NativeSearchQueryBuilder queryBuilder = new NativeSearchQueryBuilder();
queryBuilder.withQuery(QueryBuilders.matchAllQuery());
queryBuilder.addAggregation(AggregationBuilders.terms("hotWord").field(fieldName).size(10));
AggregatedPage<AnalyzerIndex> aggPage = (AggregatedPage<AnalyzerIndex>) indexRepository.search(queryBuilder.build());
Terms trem = (Terms) aggPage.getAggregation("hotWord");
AtomicInteger i = new AtomicInteger(1);
trem.getBuckets().forEach(bucket -> {
System.out.println(i.get() + ":" + bucket.getKey() + "=" + bucket.getDocCount());
i.getAndIncrement();
});
我目前的实现方案:
NativeSearchQueryBuilder queryBuilder = new NativeSearchQueryBuilder();
queryBuilder.withQuery(QueryBuilders.matchAllQuery());
queryBuilder.addAggregation(AggregationBuilders.terms("hotWord").field(fieldName).size(10));
AggregatedPage<AnalyzerIndex> aggPage = (AggregatedPage<AnalyzerIndex>) indexRepository.search(queryBuilder.build());
Terms trem = (Terms) aggPage.getAggregation("hotWord");
AtomicInteger i = new AtomicInteger(1);
trem.getBuckets().forEach(bucket -> {
System.out.println(i.get() + ":" + bucket.getKey() + "=" + bucket.getDocCount());
i.getAndIncrement();
});
2 个回复
hongsir
赞同来自:
有没有用springboot整合过es的大神,指点指点
axxc
赞同来自:
{
"aggs": {
"terms_text": {
"terms": {
"field": "text",
"size": 100,
"min_doc_count": 2,
"order": {
"_term": "desc"
}
}
}
},
"_source": {
"excludes": "text"
}
}