【问题标题】:How to specify document version in elasticsearch pipeline?如何在弹性搜索管道中指定文档版本?
【发布时间】:2017-10-24 10:51:57
【问题描述】:

我目前使用的摄取节点管道如下所示:

{
    "my-pipeline": {
        "description": "pipeline for my filebeat",
        "processors": [
            {
                "json": {
                    "field": "message",
                    "add_to_root": true,
                    "on_failure": [
                        {
                            "rename": {
                                "field": "message",
                                "target_field": "originalMessage",
                                "ignore_missing": true
                            }
                        },
                        {
                            "set": {
                                "field": "indexName",
                                "value": "pipeline-errors"
                            }
                        },
                        {
                            "set": {
                                "field": "indexType",
                                "value": "pipeline-error"
                            }
                        },
                        {
                            "rename": {
                                "field": "@timestamp",
                                "target_field": "errorTimestamp",
                                "ignore_missing": true
                            }
                        }
                    ]
                }
            },
            {
                "remove": {
                    "field": "@timestamp",
                    "ignore_failure": true
                }
            },
            {
                "remove": {
                    "field": "message",
                    "ignore_failure": true
                }
            },
            {
                "script": {
                    "inline": "ctx._index = ctx.indexName; ctx._type=ctx.indexType; if (ctx.docVersion != null) {ctx._version = ctx.docVersion; ctx._version_type='external'}"
                }
            },
            {
                "remove": {
                    "field": "indexName",
                    "ignore_failure": true
                }
            },
            {
                "remove": {
                    "field": "indexType",
                    "ignore_failure": true
                }
            }
        ]
    }
}

此管道用于简单地将由 filebeat 转发的日志拆箱。在脚本处理器中,我查找“indexName”和“indexType”字段并将其分别分配给“_index”和“_type”。由于我需要考虑版本,因此日志中包含“版本”字段(但这是可选的,因为某些日志不包含版本)。

使用此管道触发器:

org.elasticsearch.index.mapper.MapperParsingException: Cannot generate dynamic mappings of type [_version] for [_version]
    at org.elasticsearch.index.mapper.DocumentParser.createBuilderFromFieldType(DocumentParser.java:656) ~[elasticsearch-5.5.0.jar:5.5.0]
    at org.elasticsearch.index.mapper.DocumentParser.parseDynamicValue(DocumentParser.java:805) ~[elasticsearch-5.5.0.jar:5.5.0]

到目前为止我所尝试的(09-16 更新):

  • 将字段名称替换为“docVersion”之类的名称 如果它是关键字,请确保它不会发生冲突。这不起作用 太
  • 尝试使用 ctx._source.version,这会触发 ScriptException[运行时错误];毕竟,请注意 _index 和 _type 值分别来自 ctx.indexName 和 ctx.indexType
  • 也尝试在脚本上添加 'version_type=external';我仍然收到上述 MapperParsingException;
  • 尝试使用 'version_type=external_gte' 但我也遇到了 MapperParsingException

在使用 ingester 节点管道时,如何在 elasticsearch 文档中指定/使用外部版本控制?如果通过管道的脚本处理器无法做到这一点,那么在使用 filebeat-to-elasticsearch 时,有哪些选项可以使用外部版本,从而拒绝旧版本的文档?

2017 年 10 月 24 日更新 似乎这是当前弹性搜索版本(在我的情况下为 5.6)不存在的功能。根据code 中的检查,管道执行服务中的 IndexRequest 不包含对文档版本或版本类型的任何引用,因此默认为内部版本。也许这可以作为未来弹性搜索版本中的一项功能添加。

【问题讨论】:

    标签: elasticsearch


    【解决方案1】:

    以下变量可通过 ctx 映射获得:_index、_type、_id、_version、_routing、_parent、_now 和 _source。 您可以通过 ctx._source.field-name 访问字段的原始来源。

    看起来脚本正在尝试通过 ctx.version 访问名为“version”的文档字段,但该字段映射到 ctx._version。

    内部 doc 值应该检索为 ctx._source.version ,你可以试试吗?

    【讨论】:

    • 我已更新问题以反映您的建议。但是,这会触发脚本中的错误(请参阅我尝试过的 #2)
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-06-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-12-18
    • 2022-08-12
    相关资源
    最近更新 更多