elasticsearch - Logstash:从一个 Elasticsearch 迁移到另一个 Elasticsearch 结果会带来一些其他属性

标签 elasticsearch logstash amazon-elasticsearch

我一直在使用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中的文档相同

最佳答案

字段@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不再具有document_type选项。

关于elasticsearch - Logstash:从一个 Elasticsearch 迁移到另一个 Elasticsearch 结果会带来一些其他属性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58415965/

相关文章:

apache-spark - 带有Spark的Elasticsearch,基于数据框列的动态索引创建

Logstash 和 ElasticLog

elasticsearch - 为什么要使用无痛脚本将数组添加到数组?

elasticsearch - Logstash logdate类型问题

asp.net-mvc - Serilog 不会将日志写入 AWS Elasticsearch Service

amazon-web-services - 从 AWS mysql RDS 获取数据到 AWS Elasticsearch 的最简单方法?

elasticsearch - ElasticSearch 中字符串数组与串联字符串的内部结构

logging - 使用Logstash解析日志时如何添加序列ID

nginx - 带有letsencrypt的Elasticsearch Shield SSL无法签署csr错误

elasticsearch - AWS ELK - SAML SSO 在浏览器中有效,但在 iFrame 中无效