Muhammad Ateq Ejaz
Muhammad Ateq Ejaz

Reputation: 1865

Get all properties that lies within user defined polygon in Tire/Elastic search using geo_polygon filter

I'm working on a project that uses ElasticSearch and tire.I have a google map on my web page.i want to get all properties when user draw apolygon on the map that must be fetched by Elastic search with tire. i have alreday get polygon coordinates now i want to write a query in (tire.serach Block see below) that will filter all properties within polygon area.Properties table of my database has longitude and latitide column. i can do this by using Postgis adapter but i need to know the syntax of query that will do this in tire/Elastic search.

def self.search(params={}) 

tire.search(load: true, page: params[:page], per_page: 50) do |search|

  syntax of the filter query that will fetch all properties within user defined polygon area..??? 

end 
end

Thanks Ateq.

Upvotes: 3

Views: 307

Answers (1)

karmi
karmi

Reputation: 14419

Something like:

Tire.search 'venues' do
  query do
    filtered do
      query { all }
      filter :geo_polygon, location: { points: [
                                        {lat: 40, lon -70},
                                        {lat: 30, lon -80},
                                        {lat: 20, lon -90}
                                       ]
                                      }
    end
  end
end

Example adapted from Elasticsearch documentation on Geo Polygon Filter.

Upvotes: 4

Related Questions