gpt4 book ai didi

elasticsearch - 在java elasticsearch上设置字段数据= true

转载 作者:行者123 更新时间:2023-12-02 22:30:01 25 4
gpt4 key购买 nike

通过Eclipse运行Java flex 搜索查询。测试时出现此错误,并且无法在API的任何地方找到告诉我如何将该字段数据设置为true的错误

IllegalArgumentException[Fielddata is disabled on text fields by default. Set fielddata=true on [created] 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.]



有谁知道我该如何解决?

最佳答案

您必须修改索引映射属性:

try (XContentBuilder jsonBuilder = XContentFactory.jsonBuilder()) {
final XContentBuilder builder = jsonBuilder
.startObject()
.startObject("your_type")
.startObject("properties")
.startObject("your_field")
.field("type", "text")
.field("fielddata", true)/*setting fielddata*/
.endObject()
.endObject()
.endObject()
.endObject();

client.admin().indices().preparePutMapping("your_index")
.setType("your_type")
.setSource(builder)/*also there are overloads for setSource()*/
.get();
}


String source = "{\"your_type\":{\"properties\":{\"your_field\":{\"type\":\"text\",\"fielddata\":true}}}}";
client.admin().indices().preparePutMapping("your_index)
.setType("your_type")
.setSource(source, XContentType.JSON)
.get();

结果:
{
"your_index": {
"aliases": {},
"mappings": {
"your_type": {
"properties": {
...
...
"your_field": {
"type": "text",
"fielddata": true,
"fields": {
"keyword": {
"type": "keyword",
"ignore_above": 256
}
}
}
...
...
}
}
}
}
}

关于elasticsearch - 在java elasticsearch上设置字段数据= true,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44447205/

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