【问题标题】:How I need to use geo_point type with Chewy?我需要如何将 geo_point 类型与 Chewy 一起使用?
【发布时间】:2020-07-18 12:02:08
【问题描述】:

§大家好, 我对geo_point 类型定义有疑问

我的耐嚼指数代码:

class CoordinatesIndex < Chewy::Index
    define_type Coordinate.includes( :location ) do
        field :location, type: 'geo_point'
        field :user_id, type: 'integer'
        field :start_at
        field :finish_at
        field :created_at
    end
end

我也有关系坐标 has_one 位置,位置属于_to 坐标。

位置模型字段: lat,lon

我得到的错误:

{"type"=&gt;"mapper_parsing_exception", "reason"=&gt;"failed to parse field [location] of type [geo_point]", "caused_by"=&gt;{"type"=&gt;"parse_exception", "reason"=&gt;"field must be either [lat], [lon] or [geohash]"}}

为什么?

谢谢

【问题讨论】:

    标签: ruby-on-rails ruby ruby-on-rails-6 chewy-gem


    【解决方案1】:

    对于未来的 Google 员工来说,这很好用:

    field :location, type: 'geo_point', value: ->{ { lat: location.lat, lon: location.lon } }
    

    而不是

     field :location, type: 'geo_point'
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-02-23
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-09-20
      • 2020-07-03
      相关资源
      最近更新 更多