Skip to content

Instantly share code, notes, and snippets.

@rlisowski
Last active October 18, 2017 05:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rlisowski/a2c0558d8629b31123e66318a95e6a26 to your computer and use it in GitHub Desktop.
Save rlisowski/a2c0558d8629b31123e66318a95e6a26 to your computer and use it in GitHub Desktop.
MapFilter elasticsearch locations importer
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