2015-05-26 71 views
2

我打算使用弹性搜索索引来存储一个拥有大约290万条记录的庞大城市数据库,并将其用作我的Laravel应用程序的搜索引擎。如何从文本文件填充弹性搜索索引?

问题是:我都在MySQL数据库和CSV文件的城市。该文件有〜300MB。

如何将它导入索引最快?

+0

几乎是一个副本,虽然[这是关于* re * - 填充索引](http://stackoverflow.com/questions/21716002/importing-and-updating-data-in-elasticsearch)。不过,类似的问题和类似的文件大小规模。 – GolezTrol

+0

@GolezTrol这个问题没有一个明确的答案。我无法从中解压出我的问题...:/ –

+1

https://kevinkirsche.com/2014/08/25/using-logstash-to-import-csv-files-into-elasticsearch/ –

回答

4

我已经解决使用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 
    } 
} 

该脚本将导入制表符分隔文件,而无需分隔符成一个指数叫locationcity类型。

要运行该脚本,需要在安装/提取Logstash的文件夹上运行bin/logstash -f import_script_file