1

Elasticsearchのgeo_pointフィールドにTiregemでインデックスを付けようとしています。これが私のActiveRecordモデルのタイヤマッピングです:

class Availability < ActiveRecord::Base
  belongs_to :user
  attr_accessible :date, :latitude, :longitude

  include Tire::Model::Search
  include Tire::Model::Callbacks

  tire do
    mapping do
      indexes :id,                  type: 'integer',  index: 'not_analysed'
      indexes :user_id,                 type: 'integer',  index: 'not_analysed'
      indexes :user_firstname,      type: 'string',   as: 'user_firstname' 
      indexes :user_lastname,       type: 'string',   as: 'user_lastname' 
      indexes :user_level,          type: 'integer',  as: 'user_level' 
      indexes :date,                type: 'date'
      indexes :location,            type: 'geo_type', as: 'location'
    end
  end

  # def location
  #   "#{latitude},#{longitude}"
  # end

  def location
    [longitude.to_f, latitude.to_f]
  end

  def user_firstname
    user.firstname
  end

  def user_lastname
    user.lastname
  end

  def user_level
    user.level
  end
end

マッピング(bundle exec rake environment tire:import CLASS=Availability FORCE=true)を作成すると、Elasticsearchはフィールドのgeo_pointタイプを無視しているようです。location

http://localhost:9200/availabilities/_mapping呼び出しの結果は次のとおりです。

{
  availabilities: {
    availability: {
      properties: {
        date: {...},
        id: {...},
        location: {
          type: "double"
        },
        user_firstname: {...},
        user_id: {...},
        user_lastname: {...},
        user_level: {...}
      }
    }
  }
}

http://localhost:9200/availabilities/_search場所フィールドは、ドキュメント(の結果)でdoubleの配列としてインデックス付けされます。

{
  id: 8,
  ...
  location: [
    2.301643,
    48.780651
  ]
}

メソッドを次のように変更するlocationと:

  def location
    "#{latitude},#{longitude}"
  end

ドキュメント(http://www.elasticsearch.org/guide/reference/mapping/geo-point-type.html)に従ってフィールドにインデックスを付ける別のソリューションはgeo_point、ロケーションマッピングの結果です。

  location: {
    type: "string"
  },

そしてもちろん、場所フィールドは文字列としてインデックス付けされます:

{
  id: 4,
  ...
  location: "48.780651,2.301643"
}

geo_pointマッピングでが無視される理由はありますか?

ありがとう !

4

1 に答える 1

2

locationインデックスタイプのタイプが間違っていました。

geo_type代わりに使用しましたgeo_point

indexes :location, type: 'geo_point', as: 'location'
于 2013-07-04T15:17:29.110 に答える