橡皮、老虎皮、狮子皮哪一个最不好?

es2.4.0分组错误

Elasticsearch | 作者 liushui00001 | 发布于2017年03月29日 | 阅读数:3771

es.2.4.0使用聚合实现分组统计功能:按公司名称统计,例如公司名称“禅城一中队”, 统计结果为:禅,277,;城,277,;一,200;中,277;队,277。这种统计结果谁想要!!!!!!!!希望大侠帮忙看看,问题出在哪里。源码如下:
QueryBuilder queryBuilder = QueryBuilders.matchPhraseQuery("compName","禅城一中队");
TermsBuilder termsBuilder = AggregationBuilders.terms("aggCompany")
.field("compName");
SearchRequestBuilder srb = client
.prepareSearch(IndexEnum.FIRE.getName())
.setTypes(DocType.EQUIP.getName())
.setSearchType(SearchType.DFS_QUERY_THEN_FETCH)
.setSize(1000)
.setExplain(true);
srb.setQuery(queryBuilder);
srb.addAggregation(termsBuilder);
SearchResponse response = srb.execute().actionGet();
Map<String, Aggregation> companyMap = response.getAggregations()
.asMap();
StringTerms companyTerms = (StringTerms) companyMap.get("aggCompany");
logger.info("company agg size:" + companyTerms.getBuckets().size());
Iterator<Bucket> companyBucketIt = companyTerms.getBuckets().iterator();
long i = 0;
while (companyBucketIt.hasNext())
{
Bucket companyBucket = companyBucketIt.next();
logger.info("i:" + i++ + "**" + companyBucket.getKeyAsString()
+ " 单位有 " + companyBucket.getDocCount() + " 条数据");
}
已邀请:

要回复问题请先登录注册