首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Elasticsearch-Rails & Elasticsearch 5.4: Geopoint不更新

Elasticsearch-Rails & Elasticsearch 5.4: Geopoint不更新
EN

Stack Overflow用户
提问于 2017-06-19 12:53:24
回答 2查看 521关注 0票数 1

因此,我正在使用弹性搜索-rails Gem运行一个Rails 5应用程序来使用ElasticSearch5.4。

一切都很好,唯一的问题是,当我使用Geocoding更新位置以检索新的经度和纬度时,在Elasticsearch (使用Geopoint)中不会更新坐标。然而,它正确地反映在数据库中,也就是说Geocoding等工作得很好。

模型/关注点/用户_searchable.rb

代码语言:javascript
复制
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

也许有人能很快解决这个问题。

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2017-07-07 14:21:19

@Georg Keferb ck

您将创建一个实例方法位置,它将返回{ lat: lat, lon: lng },然后只需在as_indexed_json中包含这样的方法。那样的话,它会更干净,而且你也可以在以后再使用它;)

问候

票数 1
EN

Stack Overflow用户

发布于 2017-06-20 11:11:42

在开发一个低流量应用程序时,我使用了一个简单的工作方法:

当Geo_points被设置为create,而不是update时,我只需删除文档并在lat或long被访问时重新索引它。

代码语言:javascript
复制
user.__elasticsearch__.delete_document
user.__elasticsearch__.index_document

如果有人知道更好的解决方案,请张贴。我还记录了弹性搜索-rails的一个问题。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/44631151

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档