Elasticsearch 总是返回“缺少映射类型"; [英] Elasticsearch always returning "mapping type is missing"
问题描述
我正在按照此处给出的建议使用 elasticsearch 查找部分单词:
I'm following the advice given here in order to find partial words with elasticsearch:
ElasticSearch n-gram tokenfilter 找不到部分单词
我创建了一个简单的 bash 脚本来尝试运行它的一个版本:
I've created a simple bash script that attempts to run a version of this:
curl -XDELETE 10.160.86.134:9200/products
curl -XPOST 10.160.86.134:9200/products -d '{
"index": {
"number_of_shards": 1,
"analysis": {
"filter": {
"mynGram" : {"type": "nGram", "min_gram": 2, "max_gram": 10}
},
"analyzer": {
"a1" : {
"type":"custom",
"tokenizer": "standard",
"filter": ["lowercase", "mynGram"]
}
}
}
}
}
}'
curl -XPUT 10.160.86.134:9200/products/_mapping -d '{
"product" : {
"index_analyzer" : "a1",
"search_analyzer" : "standard",
"properties" : {
"product_description": {"type":"string"},
"product_name": {"type":"string"}
}
}
}'
运行此脚本后,前两个命令(转储产品,然后设置索引)似乎可以给我这个:
Following running this script the first two commands (dumping products, then setting the index) seem to work giving me this:
{"ok":true,"acknowledged":true}
{"ok":true,"acknowledged":true}
然后它在映射调用给我这个后出错:
Then it errors out following the mapping call giving me this:
{"error":"ActionRequestValidationException[Validation Failed: 1: mapping type is missing;]","status":500}
谁能看到我做错了什么?搜索 google 开始自动完成映射未找到 elasticsearch",所以这似乎是一个非常常见的错误.
Can anyone see what I'm doing wrong? Searching google starts autocompleting "mapping not found elasticsearch" so it seems to be a very common error.
推荐答案
原来这是因为映射需要应用于类型:
Turns out this is happening because the mapping needs to be applied to the type:
我试着把它应用到错误的东西上:
I tried applying it to the wrong thing:
curl -XPUT 10.160.86.134:9200/products/_mapping -d '{
它需要像这样应用于类型:
It needs to be applied to the type like so:
curl -XPUT 10.160.86.134:9200/products/product/_mapping -d '{
很遗憾,一个简单的谷歌搜索无法回答这个问题.此外,我链接到的上一篇文章非常具有误导性,答案是错误的,我也会在那里指出.
It's sad that a simple google search couldn't answer this. Also the previous post I linked to is very misleading and the answer is wrong, which I'll point out there as well.
这篇关于Elasticsearch 总是返回“缺少映射类型";的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!