Logstash:从一个弹性搜索迁移到另一个弹性搜索会产生一些其他属性



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

我们的日志配置文件

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 {
remove_fields => ["@version","@timestamp"]
}

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

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

请注意,如果您的 Amazon Elasticsearch 版本为 6.X 或更高版本,则每个索引只能使用一种文档类型,并且版本 7.X 是无类型的,此外,logstash 版本 7.X 不再具有document_type选项。

最新更新