Ingest array of JSON objects

Is it possible to import into elasticsearch an array of JSON objects?
Something like this: [{'a': 1}, {'b': 2}, ...]

Right now I get this error when trying to do so: "Malformed action/metadata line [1], expected START_OBJECT but found [START_ARRAY]"

The command I'm using is: curl -H "Content-Type: application/json" -XPOST "localhost:9200/test/_bulk?pretty&refresh" --data-binary "@test.json"


Only in one document like:

  "foo": [{'a': 1}, {'b': 2}, ...]

If your goal is to ingest multiple documents, have a look at the bulk API.

Thank you for the help.
Are we talking about this?

I'm not sure how exactly to use it to process every item in the array as a document. Is there an example that demonstrates this use case?

There's no way to send your content as is without doing any transformation first.
So use whatever language, script you want, split the array into individual documents, add a header for each and send it as a bulk request to the bulk API.

I see. Thanks again for the help :slight_smile:

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