* [docs] update readme and examples to use async/await * [apis] regenerate (including updated examples)
62 lines
1.1 KiB
Plaintext
62 lines
1.1 KiB
Plaintext
.Update document title using partial document
|
|
[source,js]
|
|
---------
|
|
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`
|
|
[source,js]
|
|
---------
|
|
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
|
|
[source,js]
|
|
---------
|
|
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”
|
|
[source,js]
|
|
---------
|
|
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'
|
|
}
|
|
}
|
|
});
|
|
---------
|