spring data elasticsearch term 聚合問題

 

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);就能夠解決
相關文章
相關標籤/搜索