简体   繁体   中英

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.

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 .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM