Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save b-mandelbrot/3161545 to your computer and use it in GitHub Desktop.
Save b-mandelbrot/3161545 to your computer and use it in GitHub Desktop.
Geo Distance Filter Support in Tire/ElasticSearch
require 'rubygems'
require 'tire'
Tire.index 'venues' do
delete
# 1) Create the index with proper mapping for the `location` property
create :mappings => { :venue => { :properties => { :location => { :type => 'geo_point' } } } }
# 2) Store some example documents of the `venue` type
store :venue, :name => 'One', :location => [40.01, -70.01]
store :venue, :name => 'Two', :location => [50, 15]
refresh
end
s = Tire.search 'venues' do
# 3) Search based on geo distance
filter 'geo_distance', :distance => '12km', :location => [40, -70]
end
s.results.each do |document|
p document
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment