gpt4 book ai didi

java - Elasticsearch Java API 迁移到TermsFacetBuilder 和AggregationBuilders

转载 作者:行者123 更新时间:2023-12-02 13:42:33 25 4
gpt4 key购买 nike

我正在从 ES 1.7 迁移到 5.2 并重构以下代码。

ES 1.7

public void prepare(final SearchRequestBuilder searchRequestBuilder) {
final TermsFacetBuilder labelsFacet = FacetBuilders
.termsFacet("labels")
.field("labels");
searchRequestBuilder.addFacet(labelsFacet);
searchRequestBuilder.setFrom(start);
searchRequestBuilder.setSize(size);
}

使用 ES 5.2

 public void prepare(final SearchRequestBuilder searchRequestBuilder) {
TermsAggregationBuilder aggregation = AggregationBuilders.terms("labels").field("labels");
searchRequestBuilder.addAggregation(aggregation);
searchRequestBuilder.setFrom(start);
searchRequestBuilder.setSize(size);
}

当我触发搜索查询时,出现以下异常

nested: IllegalArgumentException[Fielddata is disabled on text fields by default. Set fielddata=true on [labels] in order to load fielddata in memory by uninverting the inverted index. Note that this can however use significant memory.]

我还尝试在 SearchRequestBuilder 上设置 fieldDocValue 但没有成功。

最佳答案

根据错误消息,您需要enable fielddata在您的映射中。

例如,以下是在 text 字段上使用 fielddata=true 的新映射。

PUT my_index/_mapping/my_type
{
"properties": {
"my_field": {
"type": "text",
"fielddata": true
}
}
}

关于java - Elasticsearch Java API 迁移到TermsFacetBuilder 和AggregationBuilders,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42664924/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com