hi! i am a newbie to this forum and i've got a problem recently with 
relationship model search(Elasticsearch + Ruby on Rails). I have a document 
model that has_many geolocations, through georeferences. look like this 

*Document*
 has_many :geolocations, through: :georeferences
 has_many :georeferences, as: :georeferenceable, dependent: :destroy

*Georeference*
 belongs_to :georeferenceable, polymorphic: true
 belongs_to :geolocation

*Geolocation*
 has_many :georeferences
 has_many :documents, through: :georeferences

I also have a field that contain polygon data(coordinates) inside 
Geolocation. now i want to search the coordinate to return document. is it 
possible to do that ?

this is my mapping :

mapping _source: { excludes: ['attachment'] } do
    indexes :title, analyzer: 'english', index_options: 'offsets'
    indexes :attachment, type: 'attachment'
    indexes :geolocations, type: 'geo_shape'
    end
  end


this is my as_index_json

def as_indexed_json(options={})
    as_json(
      only: 'title',
      include: {geolocations: {only: [:type, :coordinates]}},
      methods: [:attachment]
      )     
  end

this is my search function

def search_lat_and_lon(radius, lat, lon)
      __elasticsearch__.search(
         {
          from: 0,
          size: 100,
          query:{
            filtered: {
              query: { 
                match_all: {} 
              }, 
              filter:{
                geo_shape: {
                  _cache: true,
                  geolocations: {
                    shape: {
                      type: "circle",
                      coordinates: [lon,lat],
                      radius: "#{radius}m"
                    }
                  }
                }
              }
            }
          }
        }
      )
    end




thanks in advance ! Help everyone can help me 

-- 
You received this message because you are subscribed to the Google Groups 
"elasticsearch" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to elasticsearch+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/elasticsearch/fdeed2d4-6b8a-40d9-9589-1682210ab52e%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to