设置处理器
编辑设置处理器
编辑设置一个字段并将其与指定的值关联。如果该字段已存在,则其值将被提供的替换。
表 41. 设置选项
名称 | 必填 | 默认值 | 描述 |
---|---|---|---|
|
是 |
- |
要插入、更新或更新的字段。支持模板片段。 |
|
是* |
- |
要为字段设置的值。支持模板片段。只能指定 |
|
否 |
- |
将复制到 |
|
否 |
|
如果 |
|
否 |
|
如果 |
|
否 |
|
用于编码 |
|
否 |
- |
处理器的描述。用于描述处理器的目的或其配置。 |
|
否 |
- |
有条件地执行处理器。请参阅有条件地运行处理器。 |
|
否 |
|
忽略处理器的错误。请参阅处理管道错误。 |
|
否 |
- |
处理处理器的错误。请参阅处理管道错误。 |
|
否 |
- |
处理器的标识符。用于调试和指标。 |
{ "description" : "sets the value of count to 1", "set": { "field": "count", "value": 1 } }
此处理器也可用于将数据从一个字段复制到另一个字段。例如
resp = client.ingest.put_pipeline( id="set_os", description="sets the value of host.os.name from the field os", processors=[ { "set": { "field": "host.os.name", "value": "{{{os}}}" } } ], ) print(resp) resp1 = client.ingest.simulate( id="set_os", docs=[ { "_source": { "os": "Ubuntu" } } ], ) print(resp1)
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
const response = await client.ingest.putPipeline({ id: "set_os", description: "sets the value of host.os.name from the field os", processors: [ { set: { field: "host.os.name", value: "{{{os}}}", }, }, ], }); console.log(response); const response1 = await client.ingest.simulate({ id: "set_os", docs: [ { _source: { os: "Ubuntu", }, }, ], }); console.log(response1);
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" } } } ] }
此处理器还可以使用点表示法访问数组字段
resp = client.ingest.simulate( pipeline={ "processors": [ { "set": { "field": "my_field", "value": "{{{input_field.1}}}" } } ] }, docs=[ { "_index": "index", "_id": "id", "_source": { "input_field": [ "Ubuntu", "Windows", "Ventura" ] } } ], ) print(resp)
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
const response = await client.ingest.simulate({ pipeline: { processors: [ { set: { field: "my_field", value: "{{{input_field.1}}}", }, }, ], }, docs: [ { _index: "index", _id: "id", _source: { input_field: ["Ubuntu", "Windows", "Ventura"], }, }, ], }); console.log(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
将字段的内容(包括数组和对象等复杂值)复制到另一个字段
resp = client.ingest.put_pipeline( id="set_bar", description="sets the value of bar from the field foo", processors=[ { "set": { "field": "bar", "copy_from": "foo" } } ], ) print(resp) resp1 = client.ingest.simulate( id="set_bar", docs=[ { "_source": { "foo": [ "foo1", "foo2" ] } } ], ) print(resp1)
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
const response = await client.ingest.putPipeline({ id: "set_bar", description: "sets the value of bar from the field foo", processors: [ { set: { field: "bar", copy_from: "foo", }, }, ], }); console.log(response); const response1 = await client.ingest.simulate({ id: "set_bar", docs: [ { _source: { foo: ["foo1", "foo2"], }, }, ], }); console.log(response1);
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" } } } ] }