Last active
October 18, 2017 05:56
-
-
Save rlisowski/a2c0558d8629b31123e66318a95e6a26 to your computer and use it in GitHub Desktop.
MapFilter elasticsearch locations importer
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class ElasticsearchLocationsImporter | |
def call | |
ElasticsearchImporter.new( | |
index_alias: 'locations', | |
mapping: mapping, | |
payload: locations_body | |
).call | |
end | |
private | |
def mapping | |
{ location: | |
{ properties: | |
{ coordinates: | |
{ type: 'geo_shape', | |
precision: '10.0m', | |
points_only: true } } } } | |
end | |
def locations_body | |
data = [] | |
(51.272..51.449).step(0.002).each do |lat| | |
(0.008..0.180).step(0.002).each do |lng| | |
data << [{ index: { _index: 'locations', _type: 'location' } }, | |
{ coordinates: | |
{ type: :point, | |
coordinates: [lng.round(3), lat.round(3)] } }] | |
end | |
end | |
data.flatten! | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment