Java使用elasticsearch进行聚合分析时出现错误

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

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. Alternatively 
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值