IMPORTANT: elasticsearch.js has been replaced by the new Elasticsearch JavaScript client. We strongly advise you to migrate to the new client. To learn more, see the migration guide.
update
editupdate
editclient.update([params, [callback]])
Update parts of a document. The required body parameter can contain one of two things:
- a partial document, which will be merged with the existing one.
-
a
script
which will update the document content
Check the API Conventions and the elasticsearch docs for more information pertaining to this method.
Update document title using partial document.
const response = await client.update({ index: 'myindex', type: 'mytype', id: '1', body: { // put the partial document under the `doc` key doc: { title: 'Updated' } } })
Add a tag to document tags
property using a script
.
const response = await client.update({ index: 'myindex', type: 'mytype', id: '1', body: { script: 'ctx._source.tags += tag', params: { tag: 'some new tag' } } });
Increment a document counter by 1 or initialize it, when the document does not exist.
const response = await client.update({ index: 'myindex', type: 'mytype', id: '777', body: { script: 'ctx._source.counter += 1', upsert: { counter: 1 } } })
Delete a document if it’s tagged “to-delete”.
const response = await client.update({ index: 'myindex', type: 'mytype', id: '1', body: { script: 'ctx._source.tags.contains(tag) ? ctx.op = "delete" : ctx.op = "none"', params: { tag: 'to-delete' } } });
Params
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|