terms 的聚合操作:
TermsAggregationBuilder termsAggregationBuilder = AggregationBuilders.terms("xxx").field("xxx");
有错误:
{ "error" : "JsonGenerationException[Can not write a field name, expecting a value]"}
解决办法:
0 实际可以不用管,忽略
1 在SearchResponse的toString()的内容如下, 这个内容就是查询的JSON结果,这里面的JSON结果的结构与SearchResponse的API操作相配套使用可以获取到里面的每一个值。
agg聚合后提示:
"message": "Could not write JSON: show_terms_doc_count_error is false; nested exception is com.fasterxml.jackson.databind.JsonMappingException: show_terms_doc_count_error is false (through reference chain: org.springframework.data.elasticsearch.core.aggregation.impl.AggregatedPageImpl[\"aggregations\"]->org.elasticsearch.search.aggregations.InternalAggregations[\"asMap\"]->java.util.Collections$UnmodifiableMap[\"campaign\"]->org.elasticsearch.search.aggregations.bucket.terms.LongTerms[\"buckets\"]->java.util.ArrayList[0]->org.elasticsearch.search.aggregations.bucket.terms.LongTerms$Bucket[\"docCountError\"])",
参考:
https://www.elastic.co/guide/en/elasticsearch/reference/5.6/search-aggregations-bucket-terms-aggregation.html#_per_bucket_document_count_error
设置:
termsAggregationBuilder.showTermDocCountError(true);
就可以解决