1
votes

is there any way to create document without indicating the _id in the URL? I understand that there is option to create document using http://localhost:9200/[index_name]/[index_type]/[_id], I do have issues creating a document using this option as my _id is not auto-generated and the _id might have special characters such as # or &. I am currently using elasticsearch version 1.3.

1

1 Answers

1
votes

One way to create documents without having to add the URL-encoded ID in the URL is to use the _bulk API. It simply goes like this:

POST index/doc/_bulk
{"index": {"_id": "1234#5678"}}
{"field": "value", "number": 34}
{"index": {"_id": "5555#7896"}}
{"field": "another", "number": 45}

As you can see, you can index several documents and their IDs is simply given within quotes inside the body of the bulk request. The URL itself simply invokes the _bulk endpoint.