Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Geospatial Searches with Searchkick to find users

I just started to use Searchkick with my Rails web service, for the moment I just testing. I want retrieve users around a certain perimeter of a location with that.

For my Test I have a User object (with email, name...), and a Position object (with longitude, latitude and a reference to one User). And User have a has_many relation with Position.

for the moment my Position look like

class Position < ActiveRecord::Base
  belongs_to :User
  searchkick locations: ["location"]

  def search_data
    attributes.merge location: [latitude, longitude]
  end
end

And I try to do a research like

Position.search *,  where: {location: {near: [50.632049, 3.068322], within: "100mi"}}

But I get the following error

nested: QueryParsingException[[positions_development_20140310223244065] failed to find geo_point field [location]]; }]","status":400}

I don't know exactly what I have to do. (I'm new to rails, and elastic search) So if someone can give me a better explanation, I take it ! Thank's

like image 282
agonist_ Avatar asked Jan 19 '26 06:01

agonist_


1 Answers

Be sure to reindex after making changes to the searchkick or search_data methods.

Position.reindex
like image 57
Andrew Kane Avatar answered Jan 20 '26 22:01

Andrew Kane