Movatterモバイル変換


[0]ホーム

URL:


Loading
  1. Elastic Docs/
  2. Reference/
  3. Elasticsearch/
  4. Processor reference

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.

NameRequiredDefaultDescription
fieldyes-The field to insert, upsert, or update. Supportstemplate snippets.
valueyes*-The value to be set for the field. Supportstemplate snippets. May specify only one ofvalue orcopy_from.
copy_fromno-The origin field which will be copied tofield, cannot setvalue simultaneously. Supported data types areboolean,number,array,object,string,date, etc.
overridenotrueIftrue processor will update fields with pre-existing non-null-valued field. When set tofalse, such fields will not be touched.
ignore_empty_valuenofalseIftrue and used in combination withvalue which is atemplate snippet that evaluates tonull or an empty string, the processor quietly exits without modifying the document. Similarly, if used in combination withcopy_from it will quietly exit if the field does not exist or its value evaluates tonull or an empty string.
media_typenoapplication/jsonThe media type for encodingvalue. Applies only whenvalue is atemplate snippet. Must be one ofapplication/json,text/plain, orapplication/x-www-form-urlencoded.
descriptionno-Description of the processor. Useful for describing the purpose of the processor or its configuration.
ifno-Conditionally execute the processor. SeeConditionally run a processor.
ignore_failurenofalseIgnore failures for the processor. SeeHandling pipeline failures.
on_failureno-Handle failures for the processor. SeeHandling pipeline failures.
tagno-Identifier for the processor. Useful for debugging and metrics.
{  "description" : "sets the value of count to 1",  "set": {    "field": "count",    "value": 1  }}

This processor can also be used to copy data from one field to another. For example:

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:

{  "docs" : [    {      "doc" : {        "_index" : "_index",        "_id" : "_id",        "_version" : "-3",        "_source" : {          "host" : {            "os" : {              "name" : "Ubuntu"            }          },          "os" : "Ubuntu"        },        "_ingest" : {          "timestamp" : "2019-03-11T21:54:37.909224Z"        }      }    }  ]}

This processor can also access array fields using dot notation:

POST /_ingest/pipeline/_simulate{  "pipeline": {    "processors": [      {        "set": {          "field": "my_field",          "value": "{{{input_field.1}}}"        }      }    ]  },  "docs": [    {      "_index": "index",      "_id": "id",      "_source": {        "input_field": [          "Ubuntu",          "Windows",          "Ventura"        ]      }    }  ]}

Result:

{  "docs": [    {      "doc": {        "_index": "index",        "_id": "id",        "_version": "-3",        "_source": {          "input_field": [            "Ubuntu",            "Windows",            "Ventura"          ],          "my_field": "Windows"        },        "_ingest": {          "timestamp": "2023-05-05T16:04:16.456475214Z"        }      }    }  ]}

The contents of a field including complex values such as arrays and objects can be copied to another field usingcopy_from:

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:

{  "docs" : [    {      "doc" : {        "_index" : "_index",        "_id" : "_id",        "_version" : "-3",        "_source" : {          "bar": ["foo1", "foo2"],          "foo": ["foo1", "foo2"]        },        "_ingest" : {          "timestamp" : "2020-09-30T12:55:17.742795Z"        }      }    }  ]}

[8]ページ先頭

©2009-2026 Movatter.jp