gpt4 book ai didi

java - "MapperParsingException[Analyzer [second] not found for field [Name]]"

转载 作者:行者123 更新时间:2023-12-02 03:41:45 25 4
gpt4 key购买 nike

我使用以下设置在 Elasticsearch 中创建了一个索引:

{
"my_index" : {
"aliases" : { },
"mappings" : { },
"settings" : {
"index" : {
"creation_date" : "1461229073677",
"uuid" : "7-TECarfRs6XO8yZE7SeWA",
"number_of_replicas" : "1",
"number_of_shards" : "5",
"version" : {
"created" : "1040599"
},
"settings" : {
"analysis" : {
"analyzer" : {
"second" : {
"type" : "custom",
"filter" : [ "lowercase", "synonym" ],
"tokenizer" : "standard"
}
},
"filter" : {
"synonym" : {
"type" : "synonym",
"synonyms" : [ "i pad => ipad", "smart phone => smartphone" ]
}
}
}
}
}
},
"warmers" : { }
}
}

现在我想做的是使用以下代码设置映射:

PutMapping putMapping = new PutMapping.Builder(
"my_index",
"my_index_type",
"{ \"properties\" : { \"Name\" : {\"type\" : \"string\", \"analyzer\" : \"second\"} } }"
).build();


JestResult result = client.execute(createIndex);
result = client.execute(putMapping);

编辑

我用来创建索引的代码是:

CreateIndex createIndex =  new CreateIndex.Builder(indexName)
.settings(
ImmutableSettings.builder()
.loadFromClasspath(
"settings.json"
).build().getAsMap()
).build();
JestResult result = client.execute(createIndex);

settings.json 如下所示:

{
"settings": {
"analysis": {
"analyzer": {
"second": {
"type": "custom",
"tokenizer": "standard",
"filter": [
"lowercase",
"synonym"
]
}
},
"filter": {
"synonym" : {
"type" : "synonym",
"synonyms" : [
"i pad => ipad",
"smart phone => smartphone",
"i phone => iphone"
]
}
}
}

}
}

但是我不断收到以下错误:

"MapperParsingException[Analyzer [second] not found for field [message]]"

如果删除“分析器”,我就可以设置映射。所以看起来我有两倍的“settings”部分,但无论我如何构建“settings.json”文件,我都会得到这两个部分。我查看了 JEST 页面中指定的示例,但没有帮助我。 https://github.com/searchbox-io/Jest/blob/master/jest/README.md

大家有什么想法吗?

最佳答案

您使用的设置未正确定义,即您有两个叠瓦状的 settings 部分,索引设置应如下所示:

{
"my_index": {
"aliases": {},
"mappings": {},
"settings": {
"index": {
"number_of_replicas": "1",
"number_of_shards": "5"
},
"analysis": {
"analyzer": {
"second": {
"type": "custom",
"filter": [
"lowercase",
"synonym"
],
"tokenizer": "standard"
}
},
"filter": {
"synonym": {
"type": "synonym",
"synonyms": [
"i pad => ipad",
"smart phone => smartphone"
]
}
}
}
},
"warmers": {}
}
}

更新

您的 settings.json 文件只需包含以下内容:

{
"analysis": {
"analyzer": {
"second": {
"type": "custom",
"filter": [
"lowercase",
"synonym"
],
"tokenizer": "standard"
}
},
"filter": {
"synonym": {
"type": "synonym",
"synonyms": [
"i pad => ipad",
"smart phone => smartphone"
]
}
}
}
}

关于java - "MapperParsingException[Analyzer [second] not found for field [Name]]",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36765019/

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