SujitS
SujitS

Reputation: 11423

How to create mapping in elasticsearch for index generated by mongo-connector

Official documentation says, we can create a mapping for string type for each index, named after the MongoDB database and collection names as animals.kitten.

I tried to create mapping as:

$ curl -XPUT 'http://localhost:9200/animals.kitten/_mapping' -d '
{
    "animals.kitten" : {
        "properties" : {
            "name" : {"type" : "string", "store" : true }
        }
    }
}'

But it throws the error as:

{
   "error": "ActionRequestValidationException[Validation Failed: 1: mapping type is missing;]",
   "status": 500
}

I dont know where I am wrong. I tried different alternatives which did not worked as well. Even though elasticsearch generate dynamic mapping for each field in index animals.kitten, it would be great if I could manually insert the mapping.

Upvotes: 2

Views: 1734

Answers (2)

SujitS
SujitS

Reputation: 11423

Sorry For the late answer but I found the way to do the mapping. The example of mapping is:

    curl -XPUT "http://localhost:9200/animals.kitten/string/_mapping" -d'{
        "string": {
            "properties" : {
            "name" : {"type" : "string", "store" : true }
             }
         }
     }'

Upvotes: 1

Olly Cruickshank
Olly Cruickshank

Reputation: 6180

Your index name is missing and your type name is inconsistent (missing the last "s"). This works:

curl -XPUT 'http://localhost:9200/myindex/animals.kittens/_mapping' -d '
{
  "animals.kittens" : {
    "properties" : {
        "name" : {"type" : "string", "store" : true }
    }
  }
}'

(you need to create the index first though)

Upvotes: 0

Related Questions