2019-03-12 14:14:41 -04:00
[[set-processor]]
=== Set Processor
Sets one field and associates it with the specified value. If the field already exists,
its value will be replaced with the provided one.
2018-12-20 08:04:54 -05:00
[[set-options]]
.Set Options
[options="header"]
|======
| Name | Required | Default | Description
| `field` | yes | - | The field to insert, upsert, or update. Supports <<accessing-template-fields,template snippets>>.
| `value` | yes | - | The value to be set for the field. Supports <<accessing-template-fields,template snippets>>.
| `override` | no | true | If processor will update fields with pre-existing non-null-valued field. When set to `false`, such fields will not be touched.
include::common-options.asciidoc[]
|======
[source,js]
--------------------------------------------------
{
2019-03-12 14:14:41 -04:00
"description" : "sets the value of count to 1"
2018-12-20 08:04:54 -05:00
"set": {
2019-03-12 14:14:41 -04:00
"field": "count",
"value": 1
2018-12-20 08:04:54 -05:00
}
}
--------------------------------------------------
// NOTCONSOLE
2019-03-12 14:14:41 -04:00
This processor can also be used to copy data from one field to another. For example:
2019-09-06 11:31:13 -04:00
[source,console]
2019-03-12 14:14:41 -04:00
--------------------------------------------------
PUT _ingest/pipeline/set_os
{
"description": "sets the value of host.os.name from the field os",
"processors": [
{
"set": {
"field": "host.os.name",
"value": "{{os}}"
}
}
]
}
POST _ingest/pipeline/set_os/_simulate
{
"docs": [
{
"_source": {
"os": "Ubuntu"
}
}
]
}
--------------------------------------------------
Result:
2019-09-06 16:09:09 -04:00
[source,console-result]
2019-03-12 14:14:41 -04:00
--------------------------------------------------
{
"docs" : [
{
"doc" : {
"_index" : "_index",
"_type" : "_doc",
"_id" : "_id",
"_source" : {
"host" : {
"os" : {
"name" : "Ubuntu"
}
},
"os" : "Ubuntu"
},
"_ingest" : {
"timestamp" : "2019-03-11T21:54:37.909224Z"
}
}
}
]
}
--------------------------------------------------
// TESTRESPONSE[s/2019-03-11T21:54:37.909224Z/$body.docs.0.doc._ingest.timestamp/]