Curl XPOST not working after upgrading from Elastic v7 to Elastic v8

This is an example of a json file I am trying to POST into elasticsearch:

{"index": {}}
{"topic": "example1", "size": 2192, "timestamp": "2024-01-10"}
{"index": {}}
{"topic": "example2", "size": 2052, "timestamp": "2024-01-10"}
{"index": {}}
{"topic": "example3", "size": 1405, "timestamp": "2024-01-10"}
{"index": {}}
{"topic": "example4", "size": 1164, "timestamp": "2024-01-10"}

This is the command I was using when I was still in elastic v7 (and it was working):

curl -vvv -sk -u "test:password" -XPOST "https://<url>/acc-index-storage-sizes/_doc/_bulk?pretty"  -H 'Content-Type: application/json' --data-binary "@outfile.json"

When I migrated to v8, I had to update my command to:

curl -s -k -H "Authorization: ApiKey $ApiKey" -XPOST "https://<api url>/acc-index-storage-sizes/_doc/_bulk?pretty"  -H 'Content-Type: application/json' --data-binary "@outfile.json"

However, I keep on encountering this error:

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

Anyone familiar with this? I tried looking for documentations and it said to put _bulk but I already included it in the POST command.

Hi,

Try to validate your JSON file using a JSON validator tool. This can help you identify any syntax errors or formatting issues in your JSON file.

JSON Online Validator and Formatter - JSON Lint

Regards

One thing that has changed between v7 and v8 is that document types now are deprecated, although I think you can configure it to use compatibility mode.

What happens if you remove the document type (_doc) and try the following:

curl -s -k -H "Authorization: ApiKey $ApiKey" -XPOST "https:///acc-index-storage-sizes/_bulk?pretty" -H 'Content-Type: application/json' --data-binary "@outfile.json"

1 Like

Hi, I tried validating it but it failed. However, what boggles my mind is that there was no problem with the format when I was using to to XPOST to elastic v7, the POST was successful every time. For elastic v8, I'm still using the same exact format yet it fails.

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.