本文档描述了如何在 OpenSearch 摄入管道中使用 drop
处理器。如果您的用例涉及大型或复杂数据集,请考虑使用在 OpenSearch 集群上运行的 Data Prepper drop_events
处理器。
Drop 处理器
drop
处理器用于丢弃文档而不对其进行索引。这对于根据特定条件阻止文档被索引非常有用。例如,您可以使用 drop
处理器来阻止缺少重要字段或包含敏感信息的文档被索引。
drop
处理器在丢弃文档时不会引发任何错误,这使得它在防止索引问题的同时不会在 OpenSearch 日志中充斥错误消息。
语法示例
以下是 drop
处理器语法
{
"drop": {
"if": "ctx.foo == 'bar'"
}
}
配置参数
下表列出了 drop
处理器的必需和可选参数。
参数 | 必需 | 描述 |
---|---|---|
描述 | 可选 | 处理器的简要描述。 |
如果 | 可选 | 运行处理器的条件。 |
ignore_failure | 可选 | 如果设置为 true ,则忽略失败。默认值为 false 。有关更多信息,请参阅处理管道失败。 |
on_failure | 可选 | 处理器失败时要运行的处理器列表。有关更多信息,请参阅处理管道失败。 |
tag | 可选 | 处理器的标识符标签。在调试时,对于区分相同类型的处理器非常有用。 |
使用处理器
按照以下步骤在管道中使用处理器。
步骤 1:创建管道
以下查询创建一个名为 drop-pii
的管道,该管道使用 drop
处理器来阻止包含个人可识别信息 (PII) 的文档被索引:
PUT /_ingest/pipeline/drop-pii
{
"description": "Pipeline that prevents PII from being indexed",
"processors": [
{
"drop": {
"if" : "ctx.user_info.contains('password') || ctx.user_info.contains('credit card')"
}
}
]
}
步骤 2(可选):测试管道
建议您在摄入文档之前测试您的管道。
要测试管道,请运行以下查询
POST _ingest/pipeline/drop-pii/_simulate
{
"docs": [
{
"_index": "testindex1",
"_id": "1",
"_source": {
"user_info": "Sensitive information including credit card"
}
}
]
}
响应
以下示例响应确认管道按预期工作(文档已被丢弃):
{
"docs": [
null
]
}
步骤 3:摄取文档
以下查询将文档摄取到名为 testindex1
的索引中
PUT testindex1/_doc/1?pipeline=drop-pii
{
"user_info": "Sensitive information including credit card"
}
以下响应确认 ID 为 1
的文档未被索引:
{ “_index”: “testindex1”, “_id”: “1”, “_version”: -3, “result”: “noop”, “_shards”: { “total”: 0, “successful”: 0, “failed”: 0 } }