【问题标题】:Logstash: Migrating from one elastic search to another elastic search result in some additional propertiesLogstash:从一个弹性搜索迁移到另一个弹性搜索会导致一些附加属性
【发布时间】:2020-02-13 09:23:49
【问题描述】:

我一直在使用 Logstash 将其中一个索引从自托管 Elasticsearch 迁移到 Amazon ElasticSearch。成功迁移后,我们发现文档中添加了一些额外的字段。我们如何防止它被添加

我们的 Logstash 配置文件

input {
 elasticsearch {
 hosts => ["https://staing-example.com:443"]
 user => "userName"
 password => "password"
 index => "testingindex"
 size => 100
 scroll => "1m"
 }
}

filter {

}

output {
 amazon_es {
 hosts => ["https://example.us-east-1.es.amazonaws.com:443"]
 region => "us-east-1"
 aws_access_key_id => "access_key_id"
 aws_secret_access_key => "access_key_id"
 index => "testingindex"
}
stdout{
  codec => rubydebug
  }
}

我们自托管的 ElasticSearch 中的文档

{
        "_index": "testingindex",
        "_type": "interaction-3",
        "_id": "38b23e7a-eafd-4163-a9f0-e2d9ffd5d2cf",
        "_score": 1,
        "_source": {
           "customerId" : [
            "e177c1f8-1fbd-4b2e-82b8-760536e42742"
          ],
          "customProperty" : {
            "messageFrom" : [
              "BOT"
            ]
          },
          "userId" : [
            "e177c1f8-1fbd-4b2e-82b8-760536e42742"
          ],
          "uniqueIdentifier" : "2b027fc0-a517-49a7-a71f-8732044cb249",
          "accountId" : "724bee3e-38f8-4538-b944-f3e21c518437"
        }
      }

我们的 Amazon ElasticSearch 中的文档

   {
        "_index" : "testingindex",
        "_type" : "doc",
        "_id" : "B-hP020Bd2lcvg9lTyBH",
        "_score" : 1.0,
        "_source" : {
          "customerId" : [
            "e177c1f8-1fbd-4b2e-82b8-760536e42742"
          ],
          "customProperty" : {
            "messageFrom" : [
              "BOT"
            ]
          },
          "@version" : "1",
          "userId" : [
            "e177c1f8-1fbd-4b2e-82b8-760536e42742"
          ],
          "@timestamp" : "2019-10-16T06:44:13.154Z",
          "uniqueIdentifier" : "2b027fc0-a517-49a7-a71f-8732044cb249",
          "accountId" : "724bee3e-38f8-4538-b944-f3e21c518437"
        }
      }

@Version 和 @Timestamp 是文档中新添加的两个字段

谁能解释为什么要添加它,还有其他方法可以防止这种情况吗? 当您比较两个文档时,_type_id 也发生了变化,我们需要 _type_id 与我们在自托管 Elasticsearch 中的文档相同

【问题讨论】:

    标签: elasticsearch logstash amazon-elasticsearch


    【解决方案1】:

    @version@timestamp 字段由 logstash 生成,如果您不想要它们,则需要使用 mutate 过滤器来删除。

    mutate {
        remove_fields => ["@version","@timestamp"]
    }
    

    要保留原始文档的 _type_id,您需要更改输入并添加选项 docinfo => true 以将这些字段放入 @metadata 字段并在输出中使用它们, documentation 有一个例子。

    input {
        elasticsearch {
            ...
            docinfo => true
        }
    
    output {
        elasticsearch {
            ...
            document_type => "%{[@metadata][_type]}"
            document_id => "%{[@metadata][_id]}"
        }
    }
    
    

    请注意,如果您的 Amazon Elasticsearch 版本为 6.X 或更高版本,则每个索引只能有一种文档类型,并且版本 7.X 是 typeless,此外,logstash 版本 7.X 没有 @987654331 @ 选项了。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2023-03-27
      • 2014-01-06
      • 1970-01-01
      • 2014-03-26
      • 1970-01-01
      • 2017-11-25
      • 2023-02-01
      相关资源
      最近更新 更多