According to the description the id parameter is optional in create API. But the typescript definition of RequestParams.Create is not defining the id as optional. So when I am calling the client.create method in typescript, it gives me the error that id is mandatory.
Steps to reproduce the behavior:
1) Try create a new document without assigning the id field.
client.create({
"index":"test-index",
"body":{
"field":"name",
"newValue":"test"
}
});
2) It will give the following error:
(node:58123) UnhandledPromiseRejectionWarning: ConfigurationError: Missing required parameter: id
at create (/Users/faizi/node_modules/@elastic/elasticsearch/api/api/create.js:57:19)
id is not set then it will create a new id by itself.@elastic/elasticsearch version: >=7.6.1Hello! The behavior of the client is correct :)
We do offer two API for indexing documents to Elasticsearch, index and create.
The difference is that the create API requires an id, while in the index API is optional. You can see it in the documentation you have linked as well:
Index API:
PUT /<index>/_doc/<_id>
POST /<index>/_doc/
Create API:
PUT /<index>/_create/<_id>
POST /<index>/_create/<_id>
Furthermore the log you have added:
(node:58123) UnhandledPromiseRejectionWarning: ConfigurationError: Missing required parameter: id
at create (/Users/faizi/node_modules/@elastic/elasticsearch/api/api/create.js:57:19)
Suggest me that you are not using a try/catch or a catch handler in your application. I highly recommend you to do so, as not using it could lead to risky memory leaks. To enforce Node.js to exit when there is a UnhandledPromiseRejectionWarning, I recommend you to use make-promises-safe :)
Hi @delvedor, also encountered this at https://github.com/elastic/elasticsearch-js/issues/1372, does this mean that the create operation on client.bulk has the incorrect behaviour since it allows creating of the document even if _id is not provided?
Since it actually makes sense for the user to use the index op when there's no document _id yet, what do you think?