Elasticsearch always returning "mapping type is missing"

LuceneElasticsearch

Lucene Problem Overview


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

https://stackoverflow.com/questions/5044674/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.

Lucene Solutions


Solution 1 - Lucene

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.

Solution 2 - Lucene

Set mapping for the index is possible in Elastic search. I tried this with the latest version of Elastic search 1.7.3 and I was able to set the mapping successfully to the index.

I tried the following,

Solution 3 - Lucene

I think Travis was right, maybe this error came from some old version of ES, a "type" in some old version of ES is just like a table in the relational database, an "index" is like a database, a "doc" is like a record. Nowadays, the "type" seemed to disappear.

you can see this from here. enter image description here

I don't know why I can't upload a picture.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionTravisView Question on Stackoverflow
Solution 1 - LuceneTravisView Answer on Stackoverflow
Solution 2 - LuceneThamizharasuView Answer on Stackoverflow
Solution 3 - LuceneYu ChaiView Answer on Stackoverflow