设置处理器
编辑设置处理器编辑
设置一个字段并将其与指定的值关联。如果该字段已存在,则其值将被替换为提供的值。
表 40. 设置选项
名称 | 必需 | 默认 | 描述 |
---|---|---|---|
|
是 |
- |
要插入、更新或更新的字段。支持 模板片段。 |
|
是* |
- |
要为该字段设置的值。支持 模板片段。只能指定 |
|
否 |
- |
将被复制到 |
|
否 |
|
如果为 |
|
否 |
|
如果为 |
|
否 |
|
用于编码 |
|
否 |
- |
处理器的描述。用于描述处理器的用途或其配置。 |
|
否 |
- |
有条件地执行处理器。请参阅 有条件地运行处理器。 |
|
否 |
|
忽略处理器的故障。请参阅 处理管道故障。 |
|
否 |
- |
处理处理器的故障。请参阅 处理管道故障。 |
|
否 |
- |
处理器的标识符。用于调试和指标。 |
{ "description" : "sets the value of count to 1", "set": { "field": "count", "value": 1 } }
此处理器也可用于将数据从一个字段复制到另一个字段。例如
response = client.ingest.put_pipeline( id: 'set_os', body: { description: 'sets the value of host.os.name from the field os', processors: [ { set: { field: 'host.os.name', value: '{{{os}}}' } } ] } ) puts response response = client.ingest.simulate( id: 'set_os', body: { docs: [ { _source: { os: 'Ubuntu' } } ] } ) puts response
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" } } ] }
结果
{ "docs" : [ { "doc" : { "_index" : "_index", "_id" : "_id", "_version" : "-3", "_source" : { "host" : { "os" : { "name" : "Ubuntu" } }, "os" : "Ubuntu" }, "_ingest" : { "timestamp" : "2019-03-11T21:54:37.909224Z" } } } ] }
此处理器还可以使用点符号访问数组字段
response = client.ingest.simulate( body: { pipeline: { processors: [ { set: { field: 'my_field', value: '{{{input_field.1}}}' } } ] }, docs: [ { _index: 'index', _id: 'id', _source: { input_field: [ 'Ubuntu', 'Windows', 'Ventura' ] } } ] } ) puts response
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" ] } } ] }
结果
{ "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" } } } ] }
可以使用 copy_from
将字段的内容(包括数组和对象等复杂值)复制到另一个字段
response = client.ingest.put_pipeline( id: 'set_bar', body: { description: 'sets the value of bar from the field foo', processors: [ { set: { field: 'bar', copy_from: 'foo' } } ] } ) puts response response = client.ingest.simulate( id: 'set_bar', body: { docs: [ { _source: { foo: [ 'foo1', 'foo2' ] } } ] } ) puts response
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"] } } ] }
结果
{ "docs" : [ { "doc" : { "_index" : "_index", "_id" : "_id", "_version" : "-3", "_source" : { "bar": ["foo1", "foo2"], "foo": ["foo1", "foo2"] }, "_ingest" : { "timestamp" : "2020-09-30T12:55:17.742795Z" } } } ] }