所以我正在使用elasticsearch-rails寶石與Elasticsearch 5.4工作一個Rails 5應用程序。Elasticsearch-Rails的&Elasticsearch 5.4:GeoPoint對象不更新
一切工作正常,我遇到的唯一問題是,當我使用地理編碼更新位置來檢索新的經度和緯度時,座標不會在Elasticsearch(使用Geopoint)中得到更新。但是,它正確地反映在數據庫中,這意味着地理編碼等工作正常。
型號/顧慮/ user_searchable.rb
include Elasticsearch::Model
include Elasticsearch::Model::Callbacks
index_name Rails.application.class.parent_name.underscore
document_type self.name.downcase
settings index: { number_of_shards: 1 } do
mapping dynamic: false do
indexes :description, analyzer: 'english'
indexes :tagline, analyzer: 'english'
indexes :username
indexes :location, type: 'geo_point'
indexes :active, type: 'boolean'
...
end
end
after_touch() { __elasticsearch__.index_document }
def as_indexed_json(_options = {})
self.as_json(
except: [:email, :lat, :lng, :status, :termsofuse, :v_code],
include: {
photos: { only: [:name, :caption, :active, :image_data] }
).merge(
location: {lat: lat, lon: lng},
age: birthday.nil? ? 18 : ((Date.today - birthday.to_date)/365.25).floor
)
end
也許有人有這種速戰速決。
你能檢查某個對象,'as_indexed_json'以檢查是否有位置呢?也許問題是你不發送位置ES上更新 – zauzaj
一件事,你確定當你更新它的保存/更新的對象也定位? – zauzaj
嗨Zauzaj,是的,有一個位置(我可以查詢它,看到它在Kibana等)。不知道您的上傳位置是什麼意思。我更新了發送到數據庫的代碼中的地理編碼lat和lon。 elasticsearch-rails更新所有屬性(位置除外)。如果我從self.as_json的except子句中刪除lat,lng,float/decimal值會得到正確更新。但是,Geo_point不會更新。這使我相信這是一個錯誤,除非有一些東西需要做,我不知道,我不能對谷歌或文檔:( –