我已使用 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/