Indexing a document without providing an ID

If you don't want to control the ID generation for the documents, you can use the POST method.

The format of this request is POST /<index>/<type>, with the JSON document as the body of the request:

POST /catalog/_doc
{
"sku": "SP000003",
"title": "Mastering Elasticsearch",
"description": "Mastering Elasticsearch",
"author": "Bharvi Dixit",
"price": 54.99
}

The ID, in this case, will be generated by Elasticsearch. It is a hash string, as highlighted in the response:

{
"_index" : "catalog",
"_type" : "_doc",
"_id" : "1ZFMpmoBa_wgE5i2FfWV",
"_version" : 1,
"result" : "created",
"_shards" : {
"total" : 2,
"successful" : 1,
"failed" : 0
},
"_seq_no" : 4,
"_primary_term" : 1
}
As per pure REST conventions, POST is used for creating a new resource and PUT is used for updating an existing resource. Here, the usage of PUT is equivalent to saying I know the ID that I want to assign, so use this ID while indexing this document
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.188.111.130