我一直在使用Logstash将其中一个索引从自托管Elasticsearch迁移到亚马逊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"
}
}我们的亚马逊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也发生了变化,我们需要与自托管Elasticsearch中的文档相同的_type和_id
发布于 2019-10-16 23:13:53
字段@version和@timestamp是由logstash生成的,如果你不需要它们,你需要使用一个变异过滤器来删除它们。
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选项。
https://stackoverflow.com/questions/58415965
复制相似问题