9

Here is my request:

POST /_bulk
{ "index" : { "_index" : "test", "_type" : "type1", "_id" : "1" } }
{"firstname":"first_name1","lastname":"last_name1"},
{"firstname":"first_name2","lastname":"last_name2"},
{"firstname":"first_name3","lastname":"last_name3"}}

Here is the error:

{    "error": "IllegalArgumentException[Malformed action/metadata line [3], expected START_OBJECT or END_OBJECT but found

[VALUE_STRING]]", "status": 500 }

Basically, each document is {"firstname": ___, "lastname": ____} I don't want to wrap them into a parent field. What am I fundamentally missing?

1

2 Answers 2

15

You're simply missing an action line for the second and third documents, try like this:

POST /_bulk
{ "index" : { "_index" : "test", "_type" : "type1", "_id" : "1" } }
{"firstname":"first_name1","lastname":"last_name1"}
{ "index" : { "_index" : "test", "_type" : "type1", "_id" : "2" } }
{"firstname":"first_name2","lastname":"last_name2"}
{ "index" : { "_index" : "test", "_type" : "type1", "_id" : "3" } }
{"firstname":"first_name3","lastname":"last_name3"}
Sign up to request clarification or add additional context in comments.

5 Comments

The Don't Repeat Yourself section suggests a way to avoid repeating _index and _type value all the time. However, please note that, action must be still specified for each document.
Of course, it's always better to specify the index and the type directly in the URL if possible. That was just to illustrate the _bulk action
yes. Earlier, I got a wrong impression when I read the document and thought that providing action at only the beginning of the file would serve the purpose well. I learnt that's not the case hard way.
Is there a way to upload a multiple json data in same index with auto id increment ? @samyak-bhuta
How to add a timeout in the above bulk request?
4

As Samyak says in his comment, "don't repeat yourself". This syntax is tidier.

post /test/_type/_bulk
{ "index": {}}
{"firstname":"first_name1","lastname":"last_name1"}
{ "index": { }}
{ "name": "Test2", "data": "This is my test data2" }

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.