Elasticsearch 7.x bulk post

Dear all,
the following body posted to http://localhost:9200/products/_bulk with appropriate content type
{ "products": ["apple", "dog", "puppy"],"user": "Sophia" }
{ "products": ["puppy","bicicle"], "user": "Jan" }
{ "products": ["apple","puppy"], "user" : "Ethan" }

is delivering

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

However, the following body posted to http://localhost:9200/products/_doc/1
{
"products" : ["apple","dog","puppy"],
"user" : "Sophia"
}

works properly.

Can you please help ?
Thankyou

Sounds like you are not following the bulk format. Have a look at https://www.elastic.co/guide/en/elasticsearch/reference/current/docs-bulk.html

Before each document, you need a metadata line as shown in the docs for the bulk API. So your example would be something like:

POST products/_bulk
{ "index" : {"_id" : "1" } }
{ "products": ["apple", "dog", "puppy"],"user": "Sophia" }
{ "index" : {"_id" : "2" } }
{ "products": ["puppy","bicicle"], "user": "Jan" }
{ "index" : {"_id" : "3" } }
{ "products": ["apple","puppy"], "user" : "Ethan" }

(providing IDs is optional, if you don't provide one, Elasticsearch will auto-generate one)

Edit: Beaten! Sorry for the double post.

1 Like

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