当我第一次创建索引然后添加带有映射的类型时,它都可以正常工作。但是当我尝试在一次调用中创建带有映射的索引时,我收到错误:
"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"
}}}}}}
答案 0 :(得分:3)
您只是错过了第二个查询中的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