Trying elasticsearch CURL to test ElastiSearch Cluster failling

10/5/2017

If I do:

curl -X POST http://elasticsearch:9200/myProject/customer/59d56aadaedef10001c4d023/_create -d @es.json

against my Elastic Cluster in Kubernetes

es.json

{
    "id": "59d56aadaedef10001c4d023",
    "displayId": "A-18",
    "agentId": "59d291aee1e6480020b5f042",
    "firstName": "Dieter",
    "lastName": "adsadsdsa",
    "birthday": "1990-01-01T00:00:00.000Z",
    "email": "adsdas@someDomain.de",
    "phone": "0912312312",
    "zipCode": "123412",
    "city": "Hannover",
    "street": "undefined"
}, query: {} 

I get:

{ "error" : "MapperParsingException[failed to parse [id]]; nested: NumberFormatException[For input string: \"59d56aadaedef10001c4d023\"]; ", "status" : 400 }

Any idea what Im doing wrong?

-- stevek
curl
elasticsearch
kubernetes

1 Answer

10/5/2017

This is a plain Elasticsearch error (nothing to do with kubernetes), caused by the dynamic mapping has already decided your id field is a number. The dynamic mapping happens when you send the field the first time and from there on you need to comply to that mapping.

You can see what the dynamic mapping has decided on by requesting the mapping of the index:

GET myProject/_mapping

A way, the best-practice way I believe, to overcome mapping problems like this is always to create the mapping first and maybe even disable the dynamic mapping (Dynamic Mapping documentation)

Add mappings either during index creation (Create Index > Mapping documentation) or afterwards (Put mappings documentation)

-- Emil Ingerslev
Source: StackOverflow