我打算使用弹性搜索索引来存储一个拥有大约290万条记录的庞大城市数据库,并将其用作我的Laravel应用程序的搜索引擎。如何从文本文件填充弹性搜索索引?
问题是:我都在MySQL数据库和CSV文件的城市。该文件有〜300MB。
如何将它导入索引最快?
我打算使用弹性搜索索引来存储一个拥有大约290万条记录的庞大城市数据库,并将其用作我的Laravel应用程序的搜索引擎。如何从文本文件填充弹性搜索索引?
问题是:我都在MySQL数据库和CSV文件的城市。该文件有〜300MB。
如何将它导入索引最快?
我已经解决使用Logstash这种进口。
我的导入脚本是这样的:
input {
file {
path => ["/home/user/location_cities.txt"]
type => "city"
start_position => "beginning"
}
}
filter {
csv {
columns => ["region", "subregion", "ufi", "uni", "dsg", "cc_fips", "cc_iso", "full_name", "full_name_nd", "sort_name", "adm1", "adm1_full_name", "adm2", "adm2_full_name"]
separator => " "
remove_field => [ "host", "message", "path" ]
}
}
output {
elasticsearch {
action => "index"
protocol => "http"
host => "127.0.0.1"
port => "9200"
index => "location"
workers => 4
}
}
该脚本将导入制表符分隔文件,而无需分隔符成一个指数叫location
与city
类型。
要运行该脚本,需要在安装/提取Logstash的文件夹上运行bin/logstash -f import_script_file
。
为了提高效率,您需要使用批量API并对数据进行块大小试验。
link to elasticsearch's documentation on bulk document indexing (importing)
如果您使用Python,看看https://pypi.python.org/pypi/esimport/0.1.9
即使使用批量API,这也非常缓慢。我使用[Logstash](https://www.elastic.co/products/logstash)进行导入,正如我在答案中所解释的那样。谢谢你的帮助。 –
几乎是一个副本,虽然[这是关于* re * - 填充索引](http://stackoverflow.com/questions/21716002/importing-and-updating-data-in-elasticsearch)。不过,类似的问题和类似的文件大小规模。 – GolezTrol
@GolezTrol这个问题没有一个明确的答案。我无法从中解压出我的问题...:/ –
https://kevinkirsche.com/2014/08/25/using-logstash-to-import-csv-files-into-elasticsearch/ –