Malformed action/metadata line [1], expected START_OBJECT but found [START_ARRAY]

I've been trying to use the bulk api to insert a large number of documents to an index.
I followed the documentation and came up with the following API call -

POST https://localhost:9200/index/_bulk
[
    {"create":{}},
    { "fileName": "filename1", "data":"massive string text data here" },
    {"create":{}},
    { "fileName": "filename2", "data":"massive string text data here" }
]

But I'm getting the following response -

{
    "error": {
        "root_cause": [
            {
                "type": "illegal_argument_exception",
                "reason": "Malformed action/metadata line [1], expected START_OBJECT but found [START_ARRAY]"
            }
        ],
        "type": "illegal_argument_exception",
        "reason": "Malformed action/metadata line [1], expected START_OBJECT but found [START_ARRAY]"
    },
    "status": 400
}

I can't seem to figure out what I'm doing wrong here.

Have a look at the docs around the bulk format. It is basically a set of lines, each holding a complete JSON object. You have array brackets at the start and end , which is incorrect. Have never used it through the Kibana dev console so am not sure if any special formatting is required.

I can't seem to find any documentation for generic api calls. Only for the language specific clients.

This link is also showcasing using array brackets to combine the multiple documents that we want to create in Elasticsearch. Also, if I remove the array brackets, the content would no longer be a valid JSON.

There are no square brackets in any of the requests in those docs. This is what it is supposed to look like.

POST _bulk
{ "index" : { "_index" : "test", "_id" : "1" } }
{ "field1" : "value1" }
{ "delete" : { "_index" : "test", "_id" : "2" } }
{ "create" : { "_index" : "test", "_id" : "3" } }
{ "field1" : "value3" }
{ "update" : {"_id" : "1", "_index" : "test"} }
{ "doc" : {"field2" : "value2"} }
1 Like

Okay so I just realised I was supposed to try this out from the kibana console. I was just making API calls using postman. This syntax worked from the kibana console. Thanks!

The same syntax applies if you send requests through Postman.

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