问题描述
Elastic管道中的各个处理器具有 on_failure
属性.这使您可以处理管道中的故障/错误.文档中的示例显示了在文档上设置其他字段.
Individual processors in an Elastic pipelines have an on_failure
attribute. This allows you to handle a failure/error in a pipeline. The example in the docs show setting an additional field on your document.
{
"description" : "my first pipeline with handled exceptions",
"processors" : [
{
"rename" : {
"field" : "foo",
"to" : "bar",
"on_failure" : [
{
"set" : {
"field" : "error.message",
"value" : "{{ _ingest.on_failure_message }}"
}
}
]
}
}
]
}
如果管道中的任何处理器出现故障,是否可以告知管道SKIP导入文档?
Is it possible to tell the pipeline to SKIP importing a document if any processors in the pipeline fail?
推荐答案
您可以劫持" drop
处理器直接跳过 on_failure
步骤中的任何一个(如果仍然要中止,则无需 _ingest.on_failure_message
):
You can "hijack" the drop
processor to skip either directly in the on_failure
step (no need for _ingest.on_failure_message
if you're aborting anyways):
{
"description": "my first pipeline with handled exceptions",
"processors": [
{
"rename" : {
"field" : "foo",
"target_field": "bar",
"on_failure" : [
{
"drop" : {
"if" : "true"
}
}
]
}
}
]
}
或将其用作单独的处理器,也许在最后,由处理器的 on_failure 中的 any 设置了
ctx.error
后代码>处理程序:
or use it as a separate processor, perhaps at the very end, after ctx.error
has been set by any of the processors' on_failure
handlers:
{
"description": "my first pipeline with handled exceptions",
"processors": [
{
"rename" : {
"field" : "foo",
"to" : "bar",
"on_failure" : [
{
"set" : {
"field" : "error.message",
"value" : "{{ _ingest.on_failure_message }}"
}
}
]
}
},
{
"drop": {
"if": "ctx.error.size() != null"
}
}
]
}
在应用管道时,这两种方法都会导致 noop
.
Both of these will result in a noop
when the pipeline is applied.
这篇关于弹性管道:失败时跳过导入的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!