我在ElasticSearch中使用geo_points时遇到了一些问题,这是我的初始设置代码 .

module Order
  module Searchable
    extend ActiveSupport::Concern

    included do
      include Elasticsearch::Model

      index_name "orders-#{Rails.env}"

      settings do
        mappings dynamic: true do
          indexes :restaurant_id, type: :integer
          indexes :delivery_address_geo, type: :geo_point
        end
      end
    end


    def as_indexed_json(_options = {})
      {
        restaurant_id: restaurant.id,
        delivery_address_geo: es_delivery_address_geo,
      }
    end

    def es_delivery_address_geo
      address = cart.shopping_order.address if delivery?
      [address.lng, address.lat] if address
    end
  end
end

module Payments
  class Order
    include ::Order::Searchable
  end
end

上面的代码具有名为“delivery_address_geo”的geo_point的映射,当我为文档做索引以便我可以检查地理位置时,我得到了错误 .

Elasticsearch :: Transport :: Transport :: Errors :: BadRequest:[400] {“error”:{“root_cause”:[{“type”:“mapper_parsing_exception”,“reason”:“无法解析”}], “type”:“mapper_parsing_exception”,“reason”:“无法解析”,“caused_by”:{“type”:“illegal_argument_exception”,“reason”:“非法纬度值[269.8383057117462] for delivery_address_geo”}},“状态“:400}

任何人都可以向我提出这个问题 . 谢谢!

================更新===============

这个问题已经解决了,问题在于lat和lng值,它们出现了错误,这就是为什么它显示错误现在我必须用聚合显示lat和long值然后如何显示它 . 以下是代码:

aggregations = {
      delivery_address_geo: { field: :delivery_address_geo}
    }

但这不起作用,我在哪里做错了?