gpt4 book ai didi

elasticsearch - 通过Logstash转储数据时如何复制elasticsearch索引的_id和_type

转载 作者:行者123 更新时间:2023-12-03 01:02:56 28 4
gpt4 key购买 nike

我有一个带有“type”:“sam”的“Index”:samcorp。

其中之一如下所示:

{
"_index": "samcorp",
"_type": "sam",
"_id": "1236",
"_version": 1,
"_score": 1,
"_source": {
"name": "Sam Smith",
"age": 22,
"confirmed": true,
"join_date": "2014-06-01"
}
}

我想将相同的数据复制到具有相同“类型”和相同“id”的不同“索引”名称“jamcorp”中

我正在使用Logstash来做到这一点:

我在logstash的配置文件中使用以下代码,但我最终得到错误的ID和类型
input {
elasticsearch {
hosts => ["127.0.0.1:9200"]
index => "samcorp"
}
}
filter {
mutate {
remove_field => [ "@version", "@timestamp" ]
}
}
output {
elasticsearch {
hosts => ["127.0.0.1:9200"]
manage_template => false
index => "jamcorp"
document_type => "%{_type}"
document_id => "%{_id}"
}
}

我尝试了所有可能的组合,我将显示以下输出:

输出:
{
"_index": "jamcorp",
"_type": "%{_type}",
"_id": "%{_id}",
"_version": 4,
"_score": 1,
"_source": {
"name": "Sam Smith",
"age": 22,
"confirmed": true,
"join_date": "2014-06-01"
}
}

我需要的Ouptut是:
{
"_index": "jamcorp",
"_type": "sam",
"_id": "1236",
"_version": 4,
"_score": 1,
"_source": {
"name": "Sam Smith",
"age": 22,
"confirmed": true,
"join_date": "2014-06-01"
}
}

任何帮助,将不胜感激。 :) 谢谢

最佳答案

elasticsearch输入中,您需要将 docinfo parameter设置为true

input {
elasticsearch {
hosts => ["127.0.0.1:9200"]
index => "samcorp"
docinfo => true <--- add this
}
}

结果, @metadata哈希将填充文档的 index_type_id,您可以在过滤器和输出中重复使用它们:
output {
elasticsearch {
hosts => ["127.0.0.1:9200"]
manage_template => false
index => "jamcorp"
document_type => "%{[@metadata][_type]}" <--- use @metadata
document_id => "%{[@metadata][_id]}" <--- use @metadata
}
}

关于elasticsearch - 通过Logstash转储数据时如何复制elasticsearch索引的_id和_type,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34878609/

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