Link Search Menu Expand Document Documentation Menu

按模式删除处理器

remove_by_pattern 处理器使用指定的通配符模式从文档中删除根级字段。

语法

以下是 remove_by_pattern 处理器的语法:

{
    "remove_by_pattern": {
        "field_pattern": "field_name_prefix*"
    }
}

配置参数

下表列出了 remove_by_pattern 处理器的必需参数和可选参数。

参数 必需/可选 描述
field_pattern 可选 删除与指定模式匹配的字段。所有元数据字段(例如 _index_version_version_type_id)如果匹配该模式,则会被忽略。此选项仅支持文档中的根级字段。
exclude_field_pattern 可选 删除不匹配指定模式的字段。所有元数据字段(例如 _index_version_version_type_id)如果与模式不匹配,则会被忽略。此选项仅支持文档中的根级字段。field_patternexclude_field_pattern 选项是互斥的。
description 可选 处理器的简要描述。
if 可选 运行处理器的条件。
ignore_failure 可选 指定即使处理器遇到错误是否继续执行。如果设置为 true,则忽略该故障。默认值为 false
on_failure 可选 处理器失败时要运行的处理器列表。
tag 可选 处理器的标识符标签。有助于调试以区分相同类型的处理器。

使用处理器

按照以下步骤在管道中使用处理器。

步骤 1:创建管道

以下查询创建一个名为 remove_fields_by_pattern 的管道,该管道删除匹配 foo* 模式的字段。

PUT /_ingest/pipeline/remove_fields_by_pattern
{
  "description": "Pipeline that removes the fields by patterns.",
  "processors": [
    {
      "remove_by_pattern": {
        "field_pattern": "foo*"
      }
    }
  ]
}

步骤 2(可选):测试管道

建议在摄取文档之前测试您的管道。

要测试管道,请运行以下查询

POST _ingest/pipeline/remove_fields_by_pattern/_simulate
{
  "docs": [
    {
      "_index": "testindex1",
      "_id": "1",
      "_source":{
         "foo1": "foo1",
         "foo2": "foo2",
         "bar": "bar"
      }
    }
  ]
}

响应

以下示例响应确认管道按预期工作

{
  "docs": [
    {
      "doc": {
        "_index": "testindex1",
        "_id": "1",
        "_source": {
          "bar": "bar"
        },
        "_ingest": {
          "timestamp": "2023-08-24T18:02:13.218986756Z"
        }
      }
    }
  ]
}

步骤 3:摄取文档

以下查询将文档摄取到名为 testindex1 的索引中

PUT testindex1/_doc/1?pipeline=remove_fields_by_pattern
{
  "foo1": "foo1",
  "foo2": "foo2",
  "bar": "bar"
}

步骤 4(可选):检索文档

要检索文档,请运行以下查询

GET testindex1/_doc/1

剩余 350 字符

有问题?

想做贡献?