gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-02 23:12:43 25 4
gpt4 key购买 nike

我一直在使用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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com