Home > Enterprise >  A mapper_parsing_exception occurred when using the bulk API of Elasticsearch
A mapper_parsing_exception occurred when using the bulk API of Elasticsearch

Time:11-29

Elasticsearch version: 8.3.3

Indexing was performed using the following Elasticsearch API.

curl -X POST "localhost:9200/bulk_meta/_doc/_bulk?pretty" -H 'Content-Type: application/json' -d' 
{"index": { "_id": "1"}}
{"mydoc": "index action, id 1 "}
{"index": {}}
{"mydoc": "index action, id 2"}
'

In this case, the following error occurred.

{
  "error" : {
    "root_cause" : [
      {
        "type" : "mapper_parsing_exception",
        "reason" : "failed to parse"
      }
    ],
    "type" : "mapper_parsing_exception",
    "reason" : "failed to parse",
    "caused_by" : {
      "type" : "illegal_argument_exception",
      "reason" : "Malformed content, found extra data after parsing: START_OBJECT"
    }
  },
  "status" : 400
}

I've seen posts asking to add \n, but that didn't help.

CodePudding user response:

You need to remove _doc from the requst.

curl -X POST "localhost:9200/bulk_meta/_bulk?pretty" -H 'Content-Type: application/json' -d'
{"index":{"_id":"1"}}
{"mydoc":"index action, id 1 "}
{"index":{}}
{"mydoc":"index action, id 2"}
'
  • Related