gpt4 book ai didi

java - ElasticSearch Java API : Enabling fielddata on text fields

转载 作者:太空宇宙 更新时间:2023-11-04 10:53:17 26 4
gpt4 key购买 nike

我已使用 ElasticSearch Java API 创建了 ElasticSearch 索引。现在我想对此索引中存储的数据执行一些聚合,但出现以下错误:

      "reason": "Fielddata is disabled on text fields by default. Set fielddata=true on [item] 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."

正如建议的那样link ,要解决此问题,我应该在“item”文本字段上启用 fielddata,但是如何使用 ElasticSearch Java API 来做到这一点?

另一种方法可能是将“item”字段映射为 keyword ,但同样的问题:如何使用 ElasticSearch Java API 做到这一点?

最佳答案

对于新索引,您可以在创建时通过执行以下操作来设置映射:

CreateIndexRequest createIndexRequest = new CreateIndexRequest(indexName);
String source = // probably read the mapping from a file
createIndexRequest.source(source, XContentType.JSON);
restHighLevelClient.indices().create(createIndexRequest);

映射应与您针对其余端点执行的请求具有相同的格式,类似于:

{
"mappings": {
"your_type": {
"properties": {
"your_property": {
"type": "keyword"
}
}
}
}
}

关于java - ElasticSearch Java API : Enabling fielddata on text fields,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47579352/

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