java核心代码如下
SearchResponse searchResponse = client.prepareSearch(Constants.ES_INDEX_COMPANY)
.addAggregation(AggregationBuilders.terms("group_by_country").field("country")
.subAggregation(AggregationBuilders.dateHistogram("group_by_join_date").field("join_date")
.dateHistogramInterval(DateHistogramInterval.YEAR)
.subAggregation(AggregationBuilders.avg("avg_salary").field("salary"))))
.execute().actionGet();
执行结果报如下的错:
Exception in thread "main" Failed to execute phase [query], all shards failed; shardFailures {[SLYuyauWSNeIP7vedKA6JA][company][0]: RemoteTransportException[[SLYuyau][127.0.0.1:9300][indices:data/read/search[phase/query]]]; nested: IllegalArgumentException[Fielddata is disabled on text fields by default. Set fielddata=true on [country] in order to load fielddata in memory by uninverting the inverted index. Note that this can however use significant memory. Alternatively use a keyword field instead.]; }{[SLYuyauWSNeIP7vedKA6JA][company][1]: RemoteTransportException[[SLYuyau][127.0.0.1:9300][indices:data/read/search[phase/query]]]; nested: IllegalArgumentException[Fielddata is disabled on text fields by default. Set fielddata=true on [country] in order to load fielddata in memory by uninverting the inverted index. Note that this can however use significant memory. Alternatively use a keyword field instead.]; }{[SLYuyauWSNeIP7vedKA6JA][company][2]: RemoteTransportException[[SLYuyau][127.0.0.1:9300][indices:data/read/search[phase/query]]]; nested: IllegalArgumentException[Fielddata is disabled on text fields by default. Set fielddata=true on [country] in order to load fielddata in memory by uninverting the inverted index. Note that this can however use significant memory. Altern

在Java中使用Elasticsearch进行聚合分析时遇到错误,原因是字段'country'未开启fielddata。解决方案包括:查看并复制索引映射,删除索引,重新创建并设置country字段的fielddata为true,最后重新导入数据后,聚合分析成功执行。

5008

被折叠的 条评论
为什么被折叠?



