管道处理器
管道处理器
允许一个管道引用并包含另一个预定义的管道。当您有一组需要在多个管道之间共享的通用处理器时,这会非常有用。您无需在每个管道中重新定义这些通用处理器,而是可以创建一个单独的基础管道来包含这些共享处理器,然后使用管道处理器从其他管道中引用该基础管道。
以下是管道处理器
的语法。
{
"pipeline": {
"name": "general-pipeline"
}
}
配置参数
下表列出了管道处理器
的必需和可选参数。
参数 | 必需/可选 | 描述 |
---|---|---|
名称 | 必需 | 要执行的管道的名称。 |
描述 | 可选 | 处理器的目的或配置说明。 |
if | 可选 | 指定条件性执行处理器。 |
ignore_failure | 可选 | 指定忽略处理器失败。参见处理管道失败。 |
on_failure | 可选 | 指定如何处理处理器故障。请参阅处理管道故障。 |
标签 | 可选 | 处理器的一个标识符。对调试和指标很有用。 |
使用处理器
按照以下步骤在管道中使用处理器。
步骤 1:创建管道
以下查询创建了一个名为general-pipeline
的通用管道,然后创建了一个名为outer-pipeline
的新管道,该管道引用了general-pipeline
PUT _ingest/pipeline/general_pipeline
{
"description": "a general pipeline",
"processors": [
{
"uppercase": {
"field": "protocol"
},
"remove": {
"field": "name"
}
}
]
}
PUT _ingest/pipeline/outer-pipeline
{
"description": "an outer pipeline referencing the general pipeline",
"processors": [
{
"pipeline": {
"name": "general-pipeline"
}
}
]
}
步骤 2(可选):测试管道
建议在摄取文档之前测试您的管道。
要测试管道,请运行以下查询
POST _ingest/pipeline/outer-pipeline/_simulate
{
"docs": [
{
"_source": {
"protocol": "https",
"name":"test"
}
}
]
}
响应
以下示例响应确认管道按预期工作
{
"docs": [
{
"doc": {
"_index": "_index",
"_id": "_id",
"_source": {
"protocol": "HTTPS"
},
"_ingest": {
"timestamp": "2024-05-24T02:43:43.700735801Z"
}
}
}
]
}
步骤 3:摄取文档
以下查询将文档摄取到名为 testindex1
的索引中
POST testindex1/_doc/1?pipeline=outer-pipeline
{
"protocol": "https",
"name": "test"
}
响应
该请求将文档中protocol
字段转换为大写,并从索引testindex1
中删除该字段名称,如以下响应所示
{
"_index": "testindex1",
"_id": "1",
"_version": 2,
"result": "created",
"_shards": {
"total": 2,
"successful": 2,
"failed": 0
},
"_seq_no": 1,
"_primary_term": 1
}
步骤 4(可选):检索文档
要检索文档,请运行以下查询
GET testindex1/_doc/1
响应
响应显示了protocol
字段已转换为大写且字段名称已删除的文档
{
"_index": "testindex1",
"_id": "1",
"_version": 2,
"_seq_no": 1,
"_primary_term": 1,
"found": true,
"_source": {
"protocol": "HTTPS"
}
}