gpt4 book ai didi

csv - 将 csv 导入 elasticsearch

转载 作者:行者123 更新时间:2023-11-29 02:43:44 49 4
gpt4 key购买 nike

我正在做“ Elasticsearch 入门”教程。不幸的是,本教程没有涵盖将 csv 数据库导入 elasticsearch 的第一步。

我用谷歌搜索找到解决方案,但不幸的是它不起作用。这是我想要实现的目标和我拥有的目标:

我有一个文件,其中包含我要导入的数据(已简化)

id,title
10,Homer's Night Out
12,Krusty Gets Busted

我想使用 logstash 导入它。通过互联网研究后,我最终得到以下配置:

input {
file {
path => ["simpsons_episodes.csv"]
start_position => "beginning"
}
}

filter {
csv {
columns => [
"id",
"title"
]
}
}

output {
stdout { codec => rubydebug }
elasticsearch {
action => "index"
hosts => ["127.0.0.1:9200"]
index => "simpsons"
document_type => "episode"
workers => 1
}
}

我在指定文档类型时遇到了问题,所以在导入数据后我导航到 http://localhost:9200/simpsons/episode/10我希望在第 10 集中看到结果。

最佳答案

干得好,您快完成了,只是缺少文档 ID。您需要像这样修改您的 elasticsearch 输出:

elasticsearch {
action => "index"
hosts => ["127.0.0.1:9200"]
index => "simpsons"
document_type => "episode"
document_id => "%{id}" <---- add this line
workers => 1
}

在此之后,您将能够查询 ID 为 10 的剧集

GET http://localhost:9200/simpsons/episode/10

关于csv - 将 csv 导入 elasticsearch,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43701016/

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