移除处理器
remove
处理器用于从文档中移除字段。
语法
以下是 remove
处理器的语法:
{
"remove": {
"field": "field_name"
}
}
配置参数
下表列出了 remove
处理器的必需参数和可选参数。
参数 | 必需/可选 | 描述 |
---|---|---|
field | 可选 | 包含要移除数据的字段名。支持模板片段。元数据字段 _index 、_version 、_version_type 和 _id 无法移除。如果指定了 version ,则无法从摄入的文档中移除 _id 。 |
exclude_field | 可选 | 要保留的字段名。除了元数据字段之外的所有其他字段都将被移除。exclude_field 和 field 选项互斥。支持模板片段。 |
description | 可选 | 处理器的简要描述。 |
if | 可选 | 运行处理器的条件。 |
ignore_failure | 可选 | 指定即使处理器遇到错误是否继续执行。如果设置为 true ,则忽略失败。默认为 false 。 |
on_failure | 可选 | 处理器失败时要运行的处理器列表。 |
tag | 可选 | 处理器的标识符标签。有助于调试以区分相同类型的处理器。 |
使用处理器
按照以下步骤在管道中使用处理器。
步骤 1:创建管道
以下查询将创建一个名为 remove_ip
的管道,该管道从文档中移除 ip_address
字段:
PUT /_ingest/pipeline/remove_ip
{
"description": "Pipeline that excludes the ip_address field.",
"processors": [
{
"remove": {
"field": "ip_address"
}
}
]
}
步骤 2(可选):测试管道
建议在摄取文档之前测试您的管道。
要测试管道,请运行以下查询
POST _ingest/pipeline/remove_ip/_simulate
{
"docs": [
{
"_index": "testindex1",
"_id": "1",
"_source":{
"ip_address": "203.0.113.1",
"name": "John Doe"
}
}
]
}
响应
以下示例响应确认管道按预期工作
{
"docs": [
{
"doc": {
"_index": "testindex1",
"_id": "1",
"_source": {
"name": "John Doe"
},
"_ingest": {
"timestamp": "2023-08-24T18:02:13.218986756Z"
}
}
}
]
}
步骤 3:摄取文档
以下查询将文档摄取到名为 testindex1
的索引中
PUT testindex1/_doc/1?pipeline=remove_ip
{
"ip_address": "203.0.113.1",
"name": "John Doe"
}
步骤 4(可选):检索文档
要检索文档,请运行以下查询
GET testindex1/_doc/1