如何从文本文件填充弹性搜索索引?
How to Populate a Elastic Search Index from text file?
我计划使用 Elastic Search 索引来存储一个包含约 290 万条记录的巨大城市数据库,并在我的 Laravel 应用程序中将其用作搜索引擎。
问题是:我在 MySQL 数据库和 CSV 文件中都有城市。该文件有 ~300MB。
如何最快将其导入索引?
为了提高效率,您需要使用大容量 API 并试验数据的块大小。
link to elasticsearch's documentation on bulk document indexing (importing)
如果你用python,看看https://pypi.python.org/pypi/esimport/0.1.9
我已经使用 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
.
的索引中
要运行脚本,需要运行bin/logstash -f import_script_file
在你installed/extractedLogstash的文件夹。
我计划使用 Elastic Search 索引来存储一个包含约 290 万条记录的巨大城市数据库,并在我的 Laravel 应用程序中将其用作搜索引擎。
问题是:我在 MySQL 数据库和 CSV 文件中都有城市。该文件有 ~300MB。
如何最快将其导入索引?
为了提高效率,您需要使用大容量 API 并试验数据的块大小。
link to elasticsearch's documentation on bulk document indexing (importing)
如果你用python,看看https://pypi.python.org/pypi/esimport/0.1.9
我已经使用 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
.
要运行脚本,需要运行bin/logstash -f import_script_file
在你installed/extractedLogstash的文件夹。