将csv导入弹性搜索 [英] import csv into elasticsearch
问题描述
csv
数据库导入弹性搜索的第一步。 我googled找到解决方案但它不工作不幸。这是我想要实现的,我有什么:
我有一个文件,我想要导入的数据(简化)
id,title
10,Homer's Night Out
12,Krusty Gets Busted
我想使用 logstash
导入它。在互联网研究之后,我结束了以下配置:
input {
file {
path = > [simpsons_episodes.csv]
start_position => 开始
}
}
过滤器{
csv {
columns => [
id,
title
]
}
}
输出{
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}< ----添加此行
workers => 1
}
此后,您将能够查询id 10
GET http:// localhost:9200 / simpsons / episode / 10
I'm doing "elastic search getting started" tutorial. Unfortunatelly this tutorial doesn't cover first step which is importing csv
database into elasticsearch.
I googled to find solution but it doesn't work unfortunatelly. Here is what I want to achieve and what I have:
I have a file with data which I want to import (simplified)
id,title
10,Homer's Night Out
12,Krusty Gets Busted
I would like to import it using logstash
. After research over the internet I end up with following config:
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
}
}
I have a trouble with specifying document type so once data is imported and I navigate to http://localhost:9200/simpsons/episode/10 I expect to see result with episode 10.
Good job, you're almost there, you're only missing the document ID. You need to modify your elasticsearch
output like this:
elasticsearch {
action => "index"
hosts => ["127.0.0.1:9200"]
index => "simpsons"
document_type => "episode"
document_id => "%{id}" <---- add this line
workers => 1
}
After this you'll be able to query episode with id 10
GET http://localhost:9200/simpsons/episode/10
这篇关于将csv导入弹性搜索的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!