I'm doing a index / update bulk call using the client.bulk api:
When I do the insert action
{
index: 'myIndex',
type: '_doc',
body: [
// action description
{ index: { _id: docIDOne } },
// the document to index
itemOne,
// action description
{ index: { _id: docIDTwo } },
// the document to index
itemTwo,
]
}
The index action works ok. At second attempt of the index action with the same items it works as well and I get a updated value for the result field in the response:
{
"index": {
"_index": "entities",
"_type": "_doc",
"_id": "TGVCcm9u",
"_version": 4,
"result": "updated",
"_shards": {
"total": 2,
"successful": 2,
"failed": 0
},
"_seq_no": 5,
"_primary_term": 1,
"status": 200
}
Does this mean that that doc has been updated?
I have tried also to use the update action with the doc_as_upsert flag like:
elastic.bulk({
index: indexName,
type: '_doc',
body: [
// action description
{ update: { _id: docIDOne } },
// the document to index
{ doc_as_upsert : true, doc: itemOne },
// action description
{ update: { _id: docIDTwo } },
// the document to index
{ doc_as_upsert : true, doc:
},
]
});
and it gives me back a created result the first attempt, and a noop the second one. I suppose I will get a updated if it updates the content.
So the point is: which api call shall I use to perform something closer to a insert OR update: index or update with the doc_as_upsert flag?
You should use update with doc_as_upsert :)
This issue tracker should be used only for questions or issues related to the JavaScript client. If you have other general questions about Elastic I suggest you use our fantastic forum, where your question will probably help others as well :)
@delvedor thank you, I was not sure that the JavaScript API was supporting it, since in the docs there is not reference to it, I mean here.
It's not documented because only querystring parameters are documented, all supported body keys are described in https://www.elastic.co/guide/en/elasticsearch/reference/6.5/docs-update.html (you can arrive at that URL from the js docs in the body section) ;)
Most helpful comment
You should use
updatewithdoc_as_upsert:)This issue tracker should be used only for questions or issues related to the JavaScript client. If you have other general questions about Elastic I suggest you use our fantastic forum, where your question will probably help others as well :)
https://discuss.elastic.co/