elasticsearch mapping issue: failed to parse field

user342673 picture user342673 · Jan 11, 2020 · Viewed 14k times · Source

I have this mapping

PUT /mytest

{
  "mappings":{
        "properties": {
          "value": { "type": "object" }
        }
  }
}

When I insert this document

POST /mytest/_doc/4
{
  "value": { "value": "test"}
}

I got the following error:

{
  "error": {
    "root_cause": [
      {
        "type": "mapper_parsing_exception",
        "reason": "failed to parse field [value.value] of type [long] in document with id '4'. Preview of field's value: 'test'"
      }
    ],
    "type": "mapper_parsing_exception",
    "reason": "failed to parse field [value.value] of type [long] in document with id '4'. Preview of field's value: 'test'",
    "caused_by": {
      "type": "illegal_argument_exception",
      "reason": "For input string: \"test\""
    }
  },
  "status": 400
}

I know the naming convention is bad, still, this is a valid JSON request, not sure why it doesn't allow it.

Answer

James Woodruff picture James Woodruff · Jan 11, 2020

This error is telling you that you don't have a mapping for the property value within your value object property. The below example would property set the value.value property within your mytest index:

PUT mytest
{
   "mappings": {
      "properties": {
         "value": {
            "type": "object",
            "properties": {
               "value": {
                  "type": "text"
               }
            }
         }
      }
   }
}

However, I don't think that's what your intention was. As a best practice, try following the Elastic Common Schema (ECS) for naming your index properties.