0

§嗨伙计们,我对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位置,位置belongs_to坐标。

位置模型字段: lat,lon

我得到的错误:

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

为什么?

谢谢

4

1 回答 1

0

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

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

代替

 field :location, type: 'geo_point'
于 2020-04-06T13:28:15.923 回答