2013-08-29 01:24:34 +02:00
|
|
|
[[docs-update]]
|
2019-07-19 14:35:36 -04:00
|
|
|
=== Update API
|
2019-08-13 09:53:39 -07:00
|
|
|
++++
|
|
|
|
<titleabbrev>Update</titleabbrev>
|
|
|
|
++++
|
2013-08-29 01:24:34 +02:00
|
|
|
|
2019-08-13 09:53:39 -07:00
|
|
|
Updates a document using the specified script.
|
2013-08-29 01:24:34 +02:00
|
|
|
|
2019-08-13 09:53:39 -07:00
|
|
|
[[docs-update-api-request]]
|
|
|
|
==== {api-request-title}
|
2013-08-29 01:24:34 +02:00
|
|
|
|
2019-09-06 16:03:59 +08:00
|
|
|
`POST /<index>/_update/<_id>`
|
2019-08-13 09:53:39 -07:00
|
|
|
|
|
|
|
[[update-api-desc]]
|
|
|
|
==== {api-description-title}
|
|
|
|
|
|
|
|
Enables you script document updates. The script can update, delete, or skip
|
|
|
|
modifying the document. The update API also supports passing a partial document,
|
|
|
|
which is merged into the existing document. To fully replace an existing
|
|
|
|
document, use the <<docs-index_,`index` API>>.
|
|
|
|
|
|
|
|
This operation:
|
|
|
|
|
|
|
|
. Gets the document (collocated with the shard) from the index.
|
|
|
|
. Runs the specified script.
|
|
|
|
. Indexes the result.
|
|
|
|
|
|
|
|
The document must still be reindexed, but using `update` removes some network
|
|
|
|
roundtrips and reduces chances of version conflicts between the GET and the
|
|
|
|
index operation.
|
|
|
|
|
|
|
|
The `_source` field must be enabled to use `update`. In addition to `_source`,
|
|
|
|
you can access the following variables through the `ctx` map: `_index`,
|
|
|
|
`_type`, `_id`, `_version`, `_routing`, and `_now` (the current timestamp).
|
|
|
|
|
|
|
|
[[docs-update-api-path-params]]
|
|
|
|
==== {api-path-parms-title}
|
|
|
|
|
|
|
|
`<index>`::
|
|
|
|
(Required, string) Name of the target index. By default, the index is created
|
|
|
|
automatically if it doesn't exist. For more information, see <<index-creation>>.
|
|
|
|
|
|
|
|
`<_id>`::
|
|
|
|
(Required, string) Unique identifier for the document to be updated.
|
|
|
|
|
|
|
|
[[docs-update-api-query-params]]
|
|
|
|
==== {api-query-parms-title}
|
|
|
|
|
2019-08-29 09:56:10 -07:00
|
|
|
include::{docdir}/rest-api/common-parms.asciidoc[tag=if_seq_no]
|
2019-08-13 09:53:39 -07:00
|
|
|
|
2019-08-29 09:56:10 -07:00
|
|
|
include::{docdir}/rest-api/common-parms.asciidoc[tag=if_primary_term]
|
2019-08-13 09:53:39 -07:00
|
|
|
|
|
|
|
`lang`::
|
|
|
|
(Optional, string) The script language. Default: `painless`.
|
|
|
|
|
2019-08-29 09:56:10 -07:00
|
|
|
include::{docdir}/rest-api/common-parms.asciidoc[tag=refresh]
|
2019-08-13 09:53:39 -07:00
|
|
|
|
|
|
|
`retry_on_conflict`::
|
|
|
|
(Optional, integer) Specify how many times should the operation be retried when
|
|
|
|
a conflict occurs. Default: 0.
|
|
|
|
|
2019-08-29 09:56:10 -07:00
|
|
|
include::{docdir}/rest-api/common-parms.asciidoc[tag=routing]
|
2019-08-13 09:53:39 -07:00
|
|
|
|
|
|
|
`_source`::
|
|
|
|
(Optional, list) Set to `false` to disable source retrieval (default: `true`).
|
|
|
|
You can also specify a comma-separated list of the fields you want to retrieve.
|
|
|
|
|
|
|
|
`_source_excludes`::
|
|
|
|
(Optional, list) Specify the source fields you want to exclude.
|
|
|
|
|
|
|
|
`_source_includes`::
|
|
|
|
(Optional, list) Specify the source fields you want to retrieve.
|
|
|
|
|
|
|
|
include::{docdir}/rest-api/common-parms.asciidoc[tag=timeoutparms]
|
|
|
|
|
2019-08-29 09:56:10 -07:00
|
|
|
include::{docdir}/rest-api/common-parms.asciidoc[tag=wait_for_active_shards]
|
2019-08-13 09:53:39 -07:00
|
|
|
|
|
|
|
[[update-api-example]]
|
|
|
|
==== {api-examples-title}
|
|
|
|
|
|
|
|
First, let's index a simple doc:
|
2013-08-29 01:24:34 +02:00
|
|
|
|
2019-09-09 13:38:14 -04:00
|
|
|
[source,console]
|
2013-08-29 01:24:34 +02:00
|
|
|
--------------------------------------------------
|
2017-12-14 17:47:53 +01:00
|
|
|
PUT test/_doc/1
|
2016-09-13 20:54:41 +02:00
|
|
|
{
|
2013-08-29 01:24:34 +02:00
|
|
|
"counter" : 1,
|
|
|
|
"tags" : ["red"]
|
2016-09-13 20:54:41 +02:00
|
|
|
}
|
2013-08-29 01:24:34 +02:00
|
|
|
--------------------------------------------------
|
|
|
|
|
2019-08-13 09:53:39 -07:00
|
|
|
To increment the counter, you can submit an update request with the
|
|
|
|
following script:
|
2013-08-29 01:24:34 +02:00
|
|
|
|
2019-09-09 13:38:14 -04:00
|
|
|
[source,console]
|
2013-08-29 01:24:34 +02:00
|
|
|
--------------------------------------------------
|
2019-01-29 10:51:07 -08:00
|
|
|
POST test/_update/1
|
2016-09-13 20:54:41 +02:00
|
|
|
{
|
2015-05-12 10:37:22 +01:00
|
|
|
"script" : {
|
2017-06-09 08:29:25 -07:00
|
|
|
"source": "ctx._source.counter += params.count",
|
2016-06-27 09:55:16 -04:00
|
|
|
"lang": "painless",
|
2015-05-12 10:37:22 +01:00
|
|
|
"params" : {
|
|
|
|
"count" : 4
|
|
|
|
}
|
2013-08-29 01:24:34 +02:00
|
|
|
}
|
2016-09-13 20:54:41 +02:00
|
|
|
}
|
2013-08-29 01:24:34 +02:00
|
|
|
--------------------------------------------------
|
2016-09-13 20:54:41 +02:00
|
|
|
// TEST[continued]
|
2013-08-29 01:24:34 +02:00
|
|
|
|
2019-08-13 09:53:39 -07:00
|
|
|
Similarly, you could use and update script to add a tag to the list of tags
|
|
|
|
(this is just a list, so the tag is added even it exists):
|
2013-08-29 01:24:34 +02:00
|
|
|
|
2019-09-09 13:38:14 -04:00
|
|
|
[source,console]
|
2013-08-29 01:24:34 +02:00
|
|
|
--------------------------------------------------
|
2019-01-29 10:51:07 -08:00
|
|
|
POST test/_update/1
|
2016-09-13 20:54:41 +02:00
|
|
|
{
|
2015-05-12 10:37:22 +01:00
|
|
|
"script" : {
|
2017-06-09 08:29:25 -07:00
|
|
|
"source": "ctx._source.tags.add(params.tag)",
|
2016-06-27 09:55:16 -04:00
|
|
|
"lang": "painless",
|
2015-05-12 10:37:22 +01:00
|
|
|
"params" : {
|
|
|
|
"tag" : "blue"
|
|
|
|
}
|
2013-08-29 01:24:34 +02:00
|
|
|
}
|
2016-09-13 20:54:41 +02:00
|
|
|
}
|
2013-08-29 01:24:34 +02:00
|
|
|
--------------------------------------------------
|
2016-09-13 20:54:41 +02:00
|
|
|
// TEST[continued]
|
2013-08-29 01:24:34 +02:00
|
|
|
|
2019-08-13 09:53:39 -07:00
|
|
|
You could also remove a tag from the list of tags. The Painless
|
|
|
|
function to `remove` a tag takes the array index of the element
|
|
|
|
you want to remove. To avoid a possible runtime error, you first need to
|
|
|
|
make sure the tag exists. If the list contains duplicates of the tag, this
|
|
|
|
script just removes one occurrence.
|
2018-08-17 04:56:06 -04:00
|
|
|
|
2019-09-09 13:38:14 -04:00
|
|
|
[source,console]
|
2018-08-17 04:56:06 -04:00
|
|
|
--------------------------------------------------
|
2019-01-29 10:51:07 -08:00
|
|
|
POST test/_update/1
|
2018-08-17 04:56:06 -04:00
|
|
|
{
|
|
|
|
"script" : {
|
|
|
|
"source": "if (ctx._source.tags.contains(params.tag)) { ctx._source.tags.remove(ctx._source.tags.indexOf(params.tag)) }",
|
|
|
|
"lang": "painless",
|
|
|
|
"params" : {
|
|
|
|
"tag" : "blue"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
--------------------------------------------------
|
|
|
|
// TEST[continued]
|
|
|
|
|
2019-08-13 09:53:39 -07:00
|
|
|
You can also add and remove fields from a document. For example, this script
|
|
|
|
adds the field `new_field`:
|
2013-08-29 01:24:34 +02:00
|
|
|
|
2019-09-09 13:38:14 -04:00
|
|
|
[source,console]
|
2013-08-29 01:24:34 +02:00
|
|
|
--------------------------------------------------
|
2019-01-29 10:51:07 -08:00
|
|
|
POST test/_update/1
|
2016-09-13 20:54:41 +02:00
|
|
|
{
|
2017-04-24 17:06:54 -04:00
|
|
|
"script" : "ctx._source.new_field = 'value_of_new_field'"
|
2016-09-13 20:54:41 +02:00
|
|
|
}
|
2013-08-29 01:24:34 +02:00
|
|
|
--------------------------------------------------
|
2016-09-13 20:54:41 +02:00
|
|
|
// TEST[continued]
|
2013-08-29 01:24:34 +02:00
|
|
|
|
2019-08-13 09:53:39 -07:00
|
|
|
Conversely, this script removes the field `new_field`:
|
2013-08-29 01:24:34 +02:00
|
|
|
|
2019-09-09 13:38:14 -04:00
|
|
|
[source,console]
|
2013-08-29 01:24:34 +02:00
|
|
|
--------------------------------------------------
|
2019-01-29 10:51:07 -08:00
|
|
|
POST test/_update/1
|
2016-09-13 20:54:41 +02:00
|
|
|
{
|
2017-04-24 17:06:54 -04:00
|
|
|
"script" : "ctx._source.remove('new_field')"
|
2016-09-13 20:54:41 +02:00
|
|
|
}
|
2013-08-29 01:24:34 +02:00
|
|
|
--------------------------------------------------
|
2016-09-13 20:54:41 +02:00
|
|
|
// TEST[continued]
|
2013-08-29 01:24:34 +02:00
|
|
|
|
2019-08-13 09:53:39 -07:00
|
|
|
Instead of updating the document, you can also change the operation that is
|
|
|
|
executed from within the script. For example, this request deletes the doc if
|
|
|
|
the `tags` field contains `green`, otherwise it does nothing (`noop`):
|
2013-08-29 01:24:34 +02:00
|
|
|
|
2019-09-09 13:38:14 -04:00
|
|
|
[source,console]
|
2013-08-29 01:24:34 +02:00
|
|
|
--------------------------------------------------
|
2019-01-29 10:51:07 -08:00
|
|
|
POST test/_update/1
|
2016-09-13 20:54:41 +02:00
|
|
|
{
|
2015-05-12 10:37:22 +01:00
|
|
|
"script" : {
|
2017-06-09 08:29:25 -07:00
|
|
|
"source": "if (ctx._source.tags.contains(params.tag)) { ctx.op = 'delete' } else { ctx.op = 'none' }",
|
2016-06-27 09:55:16 -04:00
|
|
|
"lang": "painless",
|
2015-05-12 10:37:22 +01:00
|
|
|
"params" : {
|
2016-09-13 20:54:41 +02:00
|
|
|
"tag" : "green"
|
2015-05-12 10:37:22 +01:00
|
|
|
}
|
2013-08-29 01:24:34 +02:00
|
|
|
}
|
2016-09-13 20:54:41 +02:00
|
|
|
}
|
2013-08-29 01:24:34 +02:00
|
|
|
--------------------------------------------------
|
2016-09-13 20:54:41 +02:00
|
|
|
// TEST[continued]
|
2013-08-29 01:24:34 +02:00
|
|
|
|
2015-06-19 17:29:02 +02:00
|
|
|
[float]
|
2019-08-13 09:53:39 -07:00
|
|
|
===== Update part of a document
|
2013-08-29 01:24:34 +02:00
|
|
|
|
2018-04-03 13:53:15 +02:00
|
|
|
The following partial update adds a new field to the
|
|
|
|
existing document:
|
2013-08-29 01:24:34 +02:00
|
|
|
|
2019-09-09 13:38:14 -04:00
|
|
|
[source,console]
|
2013-08-29 01:24:34 +02:00
|
|
|
--------------------------------------------------
|
2019-01-29 10:51:07 -08:00
|
|
|
POST test/_update/1
|
2016-09-13 20:54:41 +02:00
|
|
|
{
|
2013-08-29 01:24:34 +02:00
|
|
|
"doc" : {
|
|
|
|
"name" : "new_name"
|
|
|
|
}
|
2016-09-13 20:54:41 +02:00
|
|
|
}
|
2013-08-29 01:24:34 +02:00
|
|
|
--------------------------------------------------
|
2016-09-13 20:54:41 +02:00
|
|
|
// TEST[continued]
|
2013-08-29 01:24:34 +02:00
|
|
|
|
2019-08-13 09:53:39 -07:00
|
|
|
If both `doc` and `script` are specified, then `doc` is ignored. If you
|
|
|
|
specify a scripted update, include the fields you want to update in the script.
|
2013-08-29 01:24:34 +02:00
|
|
|
|
2015-06-19 17:29:02 +02:00
|
|
|
[float]
|
2019-08-13 09:53:39 -07:00
|
|
|
===== Detect noop updates
|
2016-09-13 20:54:41 +02:00
|
|
|
|
2019-08-13 09:53:39 -07:00
|
|
|
By default updates that don't change anything detect that they don't change
|
|
|
|
anything and return `"result": "noop"`:
|
2016-09-13 20:54:41 +02:00
|
|
|
|
2019-09-09 13:38:14 -04:00
|
|
|
[source,console]
|
2014-07-14 12:43:29 -04:00
|
|
|
--------------------------------------------------
|
2019-01-29 10:51:07 -08:00
|
|
|
POST test/_update/1
|
2016-09-13 20:54:41 +02:00
|
|
|
{
|
2014-07-14 12:43:29 -04:00
|
|
|
"doc" : {
|
|
|
|
"name" : "new_name"
|
2016-09-13 20:54:41 +02:00
|
|
|
}
|
|
|
|
}
|
2014-07-14 12:43:29 -04:00
|
|
|
--------------------------------------------------
|
2016-09-13 20:54:41 +02:00
|
|
|
// TEST[continued]
|
2014-07-14 12:43:29 -04:00
|
|
|
|
2019-08-13 09:53:39 -07:00
|
|
|
If the value of `name` is already `new_name`, the update
|
|
|
|
request is ignored and the `result` element in the response returns `noop`:
|
Add _operation field to index, update, delete responses
Performing the bulk request shown in #19267 now results in the following:
```
{"_index":"test","_type":"test","_id":"1","_version":1,"_operation":"create","forced_refresh":false,"_shards":{"total":2,"successful":1,"failed":0},"status":201}
{"_index":"test","_type":"test","_id":"1","_version":1,"_operation":"noop","forced_refresh":false,"_shards":{"total":2,"successful":1,"failed":0},"status":200}
```
2016-07-26 08:16:19 -07:00
|
|
|
|
2019-09-06 09:22:08 -04:00
|
|
|
[source,console-result]
|
Add _operation field to index, update, delete responses
Performing the bulk request shown in #19267 now results in the following:
```
{"_index":"test","_type":"test","_id":"1","_version":1,"_operation":"create","forced_refresh":false,"_shards":{"total":2,"successful":1,"failed":0},"status":201}
{"_index":"test","_type":"test","_id":"1","_version":1,"_operation":"noop","forced_refresh":false,"_shards":{"total":2,"successful":1,"failed":0},"status":200}
```
2016-07-26 08:16:19 -07:00
|
|
|
--------------------------------------------------
|
|
|
|
{
|
2016-09-13 20:54:41 +02:00
|
|
|
"_shards": {
|
|
|
|
"total": 0,
|
|
|
|
"successful": 0,
|
|
|
|
"failed": 0
|
|
|
|
},
|
Add _operation field to index, update, delete responses
Performing the bulk request shown in #19267 now results in the following:
```
{"_index":"test","_type":"test","_id":"1","_version":1,"_operation":"create","forced_refresh":false,"_shards":{"total":2,"successful":1,"failed":0},"status":201}
{"_index":"test","_type":"test","_id":"1","_version":1,"_operation":"noop","forced_refresh":false,"_shards":{"total":2,"successful":1,"failed":0},"status":200}
```
2016-07-26 08:16:19 -07:00
|
|
|
"_index": "test",
|
2017-12-14 17:47:53 +01:00
|
|
|
"_type": "_doc",
|
Add _operation field to index, update, delete responses
Performing the bulk request shown in #19267 now results in the following:
```
{"_index":"test","_type":"test","_id":"1","_version":1,"_operation":"create","forced_refresh":false,"_shards":{"total":2,"successful":1,"failed":0},"status":201}
{"_index":"test","_type":"test","_id":"1","_version":1,"_operation":"noop","forced_refresh":false,"_shards":{"total":2,"successful":1,"failed":0},"status":200}
```
2016-07-26 08:16:19 -07:00
|
|
|
"_id": "1",
|
2018-08-17 04:56:06 -04:00
|
|
|
"_version": 7,
|
2019-07-19 10:57:14 -04:00
|
|
|
"_primary_term": 1,
|
|
|
|
"_seq_no": 6,
|
Enforce that responses in docs are valid json (#26249)
All of the snippets in our docs marked with `// TESTRESPONSE` are
checked against the response from Elasticsearch but, due to the
way they are implemented they are actually parsed as YAML instead
of JSON. Luckilly, all valid JSON is valid YAML! Unfurtunately
that means that invalid JSON has snuck into the exmples!
This adds a step during the build to parse them as JSON and fail
the build if they don't parse.
But no! It isn't quite that simple. The displayed text of some of
these responses looks like:
```
{
...
"aggregations": {
"range": {
"buckets": [
{
"to": 1.4436576E12,
"to_as_string": "10-2015",
"doc_count": 7,
"key": "*-10-2015"
},
{
"from": 1.4436576E12,
"from_as_string": "10-2015",
"doc_count": 0,
"key": "10-2015-*"
}
]
}
}
}
```
Note the `...` which isn't valid json but we like it anyway and want
it in the output. We use substitution rules to convert the `...`
into the response we expect. That yields a response that looks like:
```
{
"took": $body.took,"timed_out": false,"_shards": $body._shards,"hits": $body.hits,
"aggregations": {
"range": {
"buckets": [
{
"to": 1.4436576E12,
"to_as_string": "10-2015",
"doc_count": 7,
"key": "*-10-2015"
},
{
"from": 1.4436576E12,
"from_as_string": "10-2015",
"doc_count": 0,
"key": "10-2015-*"
}
]
}
}
}
```
That is what the tests consume but it isn't valid JSON! Oh no! We don't
want to go update all the substitution rules because that'd be huge and,
ultimately, wouldn't buy much. So we quote the `$body.took` bits before
parsing the JSON.
Note the responses that we use for the `_cat` APIs are all converted into
regexes and there is no expectation that they are valid JSON.
Closes #26233
2017-08-17 09:02:10 -04:00
|
|
|
"result": "noop"
|
Add _operation field to index, update, delete responses
Performing the bulk request shown in #19267 now results in the following:
```
{"_index":"test","_type":"test","_id":"1","_version":1,"_operation":"create","forced_refresh":false,"_shards":{"total":2,"successful":1,"failed":0},"status":201}
{"_index":"test","_type":"test","_id":"1","_version":1,"_operation":"noop","forced_refresh":false,"_shards":{"total":2,"successful":1,"failed":0},"status":200}
```
2016-07-26 08:16:19 -07:00
|
|
|
}
|
|
|
|
--------------------------------------------------
|
2016-09-13 20:54:41 +02:00
|
|
|
|
2019-08-13 09:53:39 -07:00
|
|
|
You can disable this behavior by setting `"detect_noop": false`:
|
2016-09-13 20:54:41 +02:00
|
|
|
|
2019-09-09 13:38:14 -04:00
|
|
|
[source,console]
|
2016-09-13 20:54:41 +02:00
|
|
|
--------------------------------------------------
|
2019-01-29 10:51:07 -08:00
|
|
|
POST test/_update/1
|
2016-09-13 20:54:41 +02:00
|
|
|
{
|
|
|
|
"doc" : {
|
|
|
|
"name" : "new_name"
|
|
|
|
},
|
2016-12-09 09:00:37 -08:00
|
|
|
"detect_noop": false
|
2016-09-13 20:54:41 +02:00
|
|
|
}
|
|
|
|
--------------------------------------------------
|
|
|
|
// TEST[continued]
|
2014-07-14 12:43:29 -04:00
|
|
|
|
2014-09-12 07:45:31 +02:00
|
|
|
[[upserts]]
|
|
|
|
[float]
|
2019-08-13 09:53:39 -07:00
|
|
|
===== Upsert
|
2015-06-19 17:29:02 +02:00
|
|
|
|
|
|
|
If the document does not already exist, the contents of the `upsert` element
|
2019-08-13 09:53:39 -07:00
|
|
|
are inserted as a new document. If the document exists, the
|
|
|
|
`script` is executed:
|
2013-08-29 01:24:34 +02:00
|
|
|
|
2019-09-09 13:38:14 -04:00
|
|
|
[source,console]
|
2013-08-29 01:24:34 +02:00
|
|
|
--------------------------------------------------
|
2019-01-29 10:51:07 -08:00
|
|
|
POST test/_update/1
|
2016-09-13 20:54:41 +02:00
|
|
|
{
|
2015-05-12 10:37:22 +01:00
|
|
|
"script" : {
|
2017-06-09 08:29:25 -07:00
|
|
|
"source": "ctx._source.counter += params.count",
|
2016-06-27 09:55:16 -04:00
|
|
|
"lang": "painless",
|
2015-05-12 10:37:22 +01:00
|
|
|
"params" : {
|
|
|
|
"count" : 4
|
|
|
|
}
|
2013-08-29 01:24:34 +02:00
|
|
|
},
|
|
|
|
"upsert" : {
|
|
|
|
"counter" : 1
|
|
|
|
}
|
2016-09-13 20:54:41 +02:00
|
|
|
}
|
2013-08-29 01:24:34 +02:00
|
|
|
--------------------------------------------------
|
2016-09-13 20:54:41 +02:00
|
|
|
// TEST[continued]
|
2015-06-19 17:29:02 +02:00
|
|
|
|
|
|
|
[float]
|
2019-04-30 10:19:09 -04:00
|
|
|
[[scripted_upsert]]
|
2019-08-13 09:53:39 -07:00
|
|
|
===== Scripted upsert
|
2015-06-19 17:29:02 +02:00
|
|
|
|
2019-08-13 09:53:39 -07:00
|
|
|
To run the script whether or not the document exists, set `scripted_upsert` to
|
|
|
|
`true`:
|
2014-08-04 09:13:10 +01:00
|
|
|
|
2019-09-09 13:38:14 -04:00
|
|
|
[source,console]
|
2014-08-04 09:13:10 +01:00
|
|
|
--------------------------------------------------
|
2019-01-29 10:51:07 -08:00
|
|
|
POST sessions/_update/dh3sgudg8gsrgl
|
2016-09-13 20:54:41 +02:00
|
|
|
{
|
2014-08-04 09:13:10 +01:00
|
|
|
"scripted_upsert":true,
|
2015-05-12 10:37:22 +01:00
|
|
|
"script" : {
|
|
|
|
"id": "my_web_session_summariser",
|
|
|
|
"params" : {
|
|
|
|
"pageViewEvent" : {
|
|
|
|
"url":"foo.com/bar",
|
|
|
|
"response":404,
|
|
|
|
"time":"2014-01-01 12:32"
|
|
|
|
}
|
2014-08-04 09:13:10 +01:00
|
|
|
}
|
|
|
|
},
|
2015-06-19 17:29:02 +02:00
|
|
|
"upsert" : {}
|
2016-09-13 20:54:41 +02:00
|
|
|
}
|
2014-08-04 09:13:10 +01:00
|
|
|
--------------------------------------------------
|
2017-06-09 08:29:25 -07:00
|
|
|
// TEST[s/"id": "my_web_session_summariser"/"source": "ctx._source.page_view_event = params.pageViewEvent"/]
|
2017-04-24 17:06:54 -04:00
|
|
|
// TEST[continued]
|
2014-08-04 09:13:10 +01:00
|
|
|
|
2015-06-19 17:29:02 +02:00
|
|
|
[float]
|
2019-04-30 10:19:09 -04:00
|
|
|
[[doc_as_upsert]]
|
2019-08-13 09:53:39 -07:00
|
|
|
===== Doc as upsert
|
2014-08-04 09:13:10 +01:00
|
|
|
|
2019-08-13 09:53:39 -07:00
|
|
|
Instead of sending a partial `doc` plus an `upsert` doc, you can set
|
|
|
|
`doc_as_upsert` to `true` to use the contents of `doc` as the `upsert`
|
2015-06-19 17:29:02 +02:00
|
|
|
value:
|
2013-08-29 01:24:34 +02:00
|
|
|
|
2019-09-09 13:38:14 -04:00
|
|
|
[source,console]
|
2013-08-29 01:24:34 +02:00
|
|
|
--------------------------------------------------
|
2019-01-29 10:51:07 -08:00
|
|
|
POST test/_update/1
|
2016-09-13 20:54:41 +02:00
|
|
|
{
|
2013-08-29 01:24:34 +02:00
|
|
|
"doc" : {
|
|
|
|
"name" : "new_name"
|
|
|
|
},
|
|
|
|
"doc_as_upsert" : true
|
2016-09-13 20:54:41 +02:00
|
|
|
}
|
2013-08-29 01:24:34 +02:00
|
|
|
--------------------------------------------------
|
2016-09-13 20:54:41 +02:00
|
|
|
// TEST[continued]
|