123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142 |
- [[set-processor]]
- === Set processor
- ++++
- <titleabbrev>Set</titleabbrev>
- ++++
- Sets one field and associates it with the specified value. If the field already exists,
- its value will be replaced with the provided one.
- [[set-options]]
- .Set Options
- [options="header"]
- |======
- | Name | Required | Default | Description
- | `field` | yes | - | The field to insert, upsert, or update. Supports <<template-snippets,template snippets>>.
- | `value` | yes* | - | The value to be set for the field. Supports <<template-snippets,template snippets>>. May specify only one of `value` or `copy_from`.
- | `copy_from` | no | - | The origin field which will be copied to `field`, cannot set `value` simultaneously. Supported data types are `boolean`, `number`, `array`, `object`, `string`, `date`, etc.
- | `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.
- | `ignore_empty_value` | no | `false` | If `true` and `value` is a <<template-snippets,template snippet>> that evaluates to `null` or the empty string, the processor quietly exits without modifying the document
- | `media_type` | no | `application/json` | The media type for encoding `value`. Applies only when `value` is a <<template-snippets,template snippet>>. Must be one of `application/json`, `text/plain`, or `application/x-www-form-urlencoded`.
- include::common-options.asciidoc[]
- |======
- [source,js]
- --------------------------------------------------
- {
- "description" : "sets the value of count to 1",
- "set": {
- "field": "count",
- "value": 1
- }
- }
- --------------------------------------------------
- // NOTCONSOLE
- This processor can also be used to copy data from one field to another. For example:
- [source,console]
- --------------------------------------------------
- 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:
- [source,console-result]
- --------------------------------------------------
- {
- "docs" : [
- {
- "doc" : {
- "_index" : "_index",
- "_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/]
- The contents of a field including complex values such as arrays and objects can be copied to another field using `copy_from`:
- [source,console]
- --------------------------------------------------
- PUT _ingest/pipeline/set_bar
- {
- "description": "sets the value of bar from the field foo",
- "processors": [
- {
- "set": {
- "field": "bar",
- "copy_from": "foo"
- }
- }
- ]
- }
- POST _ingest/pipeline/set_bar/_simulate
- {
- "docs": [
- {
- "_source": {
- "foo": ["foo1", "foo2"]
- }
- }
- ]
- }
- --------------------------------------------------
- Result:
- [source,console-result]
- --------------------------------------------------
- {
- "docs" : [
- {
- "doc" : {
- "_index" : "_index",
- "_id" : "_id",
- "_source" : {
- "bar": ["foo1", "foo2"],
- "foo": ["foo1", "foo2"]
- },
- "_ingest" : {
- "timestamp" : "2020-09-30T12:55:17.742795Z"
- }
- }
- }
- ]
- }
- --------------------------------------------------
- // TESTRESPONSE[s/2020-09-30T12:55:17.742795Z/$body.docs.0.doc._ingest.timestamp/]
|