-
-
Save b-mandelbrot/3161545 to your computer and use it in GitHub Desktop.
Geo Distance Filter Support in Tire/ElasticSearch
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
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