I would like to do a upsert for a document. Is it currently possible to do that via nodejs elasticsearch API?
https://www.elastic.co/guide/en/elasticsearch/client/javascript-api/current/api-reference.html
I looked through the API, and I could only see an upsert option for update.
Does that mean currently there aren't any way for me to upsert a document?
Thanks
Updates a document using the specified script. If the Elasticsearch security features are enabled, you must have the index or write index privilege for the target index or index alias. Enables you to script document updates.
till now there is no upsert method for NodeJS Elasticseach API so work around you can check the existence of document if it not exist insert it if it exist update it. Show activity on this post. Set the doc_as_upsert parameter to true when calling the update method to upsert a document.
If the Elasticsearch security features are enabled, you must have the index or write index privilege for the target index or index alias. Enables you to script document updates. The script can update, delete, or skip modifying the document.
By default, the document is only reindexed if the new _source field differs from the old. Setting detect_noop to false will cause Elasticsearch to always update the document, even if it hasn’t changed.
Set the doc_as_upsert
parameter to true
when calling the update
method to upsert a document.
const response = await client.update({
index: 'myindex',
type: 'mytype',
id: '1',
body: {
doc: {
title: 'Updated'
},
doc_as_upsert: true
}
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With