本文档介绍了如何在 OpenSearch 摄入管道中使用 copy
处理器。如果您的用例涉及大型或复杂数据集,请考虑使用在 OpenSearch 集群上运行的 Data Prepper copy_values
处理器。
Copy 处理器
该 copy
处理器将现有字段中的整个对象复制到另一个字段。
语法
以下是 copy
处理器的语法:
{
"copy": {
"source_field": "source_field",
"target_field": "target_field",
"ignore_missing": true,
"override_target": true,
"remove_source": true
}
}
配置参数
下表列出了 copy
处理器所需的和可选的参数。
参数 | 必需/可选 | 描述 |
---|---|---|
source_field | 必需 | 要复制的字段的名称。支持 模板片段。 |
target_field | 必需 | 要复制到的字段的名称。支持 模板片段。 |
ignore_missing | 可选 | 指定处理器是否应忽略不包含指定 source_field 的文档。如果设置为 true ,则如果 source_field 不存在或为 null ,处理器将不修改文档。默认值为 false 。 |
override_target | 可选 | 指定如果文档中已存在 target_field ,处理器是否应覆盖它。如果设置为 true ,则如果 target_field 已存在,处理器将覆盖其值。默认值为 false 。 |
remove_source | 可选 | 指定处理器在复制后是否应删除 source_field 。如果设置为 true ,处理器将从文档中删除 source_field 。默认值为 false 。 |
description | 可选 | 处理器的简要描述。 |
if | 可选 | 运行处理器的条件。 |
ignore_failure | 可选 | 指定即使遇到错误,处理器是否继续执行。如果设置为 true ,则忽略该故障。默认值为 false 。 |
on_failure | 可选 | 处理器失败时要运行的处理器列表。 |
tag | 可选 | 处理器的标识符标签。有助于调试以区分相同类型的处理器。 |
使用处理器
按照以下步骤在管道中使用处理器。
步骤 1:创建管道
以下查询创建一个名为 copy_object
的管道,该管道将嵌套对象从一个字段复制到根级别
PUT /_ingest/pipeline/copy_object
{
"description": "Pipeline that copies object.",
"processors": [
{
"copy": {
"source_field": "message.content",
"target_field":"content",
"ignore_missing": true,
"override_target": true,
"remove_source": true
}
}
]
}
步骤 2(可选):测试管道
建议在摄取文档之前测试您的管道。
要测试管道,请运行以下查询
POST _ingest/pipeline/copy_object/_simulate
{
"docs": [
{
"_index": "testindex1",
"_id": "1",
"_source":{
"message": {
"content": {
"foo": "bar",
"zoo": [1, 2, 3]
}
}
}
}
]
}
响应
以下示例响应确认管道按预期工作
{
"docs": [
{
"doc": {
"_index": "testindex1",
"_id": "1",
"_source": {
"content": {
"foo": "bar",
"zoo": [1, 2, 3]
}
},
"_ingest": {
"timestamp": "2023-08-24T18:02:13.218986756Z"
}
}
}
]
}
步骤 3:摄取文档
以下查询将文档摄取到名为 testindex1
的索引中
PUT testindex1/_doc/1?pipeline=copy_object
{
"content": {
"foo": "bar",
"zoo": [1, 2, 3]
}
}
步骤 4(可选):检索文档
要检索文档,请运行以下查询
GET testindex1/_doc/1