因此,我正在使用弹性搜索-rails Gem运行一个Rails 5应用程序来使用ElasticSearch5.4。
一切都很好,唯一的问题是,当我使用Geocoding更新位置以检索新的经度和纬度时,在Elasticsearch (使用Geopoint)中不会更新坐标。然而,它正确地反映在数据库中,也就是说Geocoding等工作得很好。
模型/关注点/用户_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也许有人能很快解决这个问题。
发布于 2017-07-07 14:21:19
@Georg Keferb ck
您将创建一个实例方法位置,它将返回{ lat: lat, lon: lng },然后只需在as_indexed_json中包含这样的方法。那样的话,它会更干净,而且你也可以在以后再使用它;)
问候
发布于 2017-06-20 11:11:42
在开发一个低流量应用程序时,我使用了一个简单的工作方法:
当Geo_points被设置为create,而不是update时,我只需删除文档并在lat或long被访问时重新索引它。
user.__elasticsearch__.delete_document
user.__elasticsearch__.index_document如果有人知道更好的解决方案,请张贴。我还记录了弹性搜索-rails的一个问题。
https://stackoverflow.com/questions/44631151
复制相似问题