gpt4 book ai didi

elasticsearch:使用映射创建索引

转载 作者:行者123 更新时间:2023-12-04 03:45:00 46 4
gpt4 key购买 nike

当我首先创建索引然后添加带有映射的类型时,一切正常。但是当我尝试在一次调用中创建一个带有映射的索引时,出现错误:

"type": "mapper_parsing_exception",
"reason": "Failed to parse mapping [my_type]: Expected map for property [fields] on field [type] but got a class java.lang.String",

如何解决?我的代码如下:

创建:

PUT /my_index
{
"settings": {
"number_of_shards": 1,
"analysis": {
"filter": {
"my_shingle_filter": {
"type": "shingle",
"min_shingle_size": 2,
"max_shingle_size": 3,
"output_unigrams": false,
"filler_token": ""
},
"kill_fillers": {
"type": "pattern_replace",
"pattern": ".*_.*",
"replace": ""
}
},
"analyzer": {
"my_shingle_analyzer": {
"type": "custom",
"tokenizer": "standard",
"filter": [
"standard"
,"lowercase"
,"stop"
,"porter_stem"
,"my_shingle_filter"
,"trim"
]
}}}}}

添加类型:

PUT /my_index/_mapping/my_type
{
"my_type": {
"properties": {
"title": {
"type": "string",
"fields": {
"shingles": {
"type": "string",
"analyzer": "my_shingle_analyzer"
}}}}}}

创建索引和映射:

PUT /my_index
{
"settings": {
"number_of_shards": 1,
"analysis": {
"filter": {
"my_shingle_filter": {
"type": "shingle",
"min_shingle_size": 2,
"max_shingle_size": 2,
"output_unigrams": false
}
},
"analyzer": {
"my_shingle_analyzer": {
"type": "custom",
"tokenizer": "standard",
"filter": [
"lowercase",
"my_shingle_filter"
]
}}}
},
"mappings": {
"my_type": {
"properties": {
"type": "string",
"fields": {
"shingles": {
"type": "string",
"analyzer": "my_shingle_analyzer"
}}}}}}

最佳答案

您只是在第二个查询中缺少 title 字段:

PUT /my_index
{
"settings": {
"number_of_shards": 1,
"analysis": {
"filter": {
"my_shingle_filter": {
"type": "shingle",
"min_shingle_size": 2,
"max_shingle_size": 2,
"output_unigrams": false
}
},
"analyzer": {
"my_shingle_analyzer": {
"type": "custom",
"tokenizer": "standard",
"filter": [
"lowercase",
"my_shingle_filter"
]
}}}
},
"mappings": {
"my_type": {
"properties": {
"title": { <--- this line is missing
"type": "string",
"fields": {
"shingles": {
"type": "string",
"analyzer": "my_shingle_analyzer"
}}}}}}} <--- + one closing brace

关于elasticsearch:使用映射创建索引,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34749919/

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