Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
883 views
in Technique[技术] by (71.8m points)

lucene - Elasticsearch always returning "mapping type is missing"

I'm following the advice given here in order to find partial words with elasticsearch:

ElasticSearch n-gram tokenfilter not finding partial words

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}

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.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...