2012-11-06 2 views
1

타이어 젬으로 Elasticsearch의 geo_point 필드를 인덱싱하려고합니다.타이어로 ElasticSearch의 geo_point 필드 매핑하기

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가 location 필드의 geo_point 유형을 무시하는 것 : 여기 내 액티브 모델에 대한 내 타이어 매핑입니다. I가 변경되면

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

:

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

위치 필드가 문서에 이중의 배열로 인덱싱 (http://localhost:9200/availabilities/_search 결과) 여기

http://localhost:9200/availabilities/_mapping 호출의 결과 location 방법 :

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

문서 (http://www.elasticsearch.org/guide/reference/mapping/geo-point-type.html)에 따라 geo_point 필드를 색인하는 또 다른 해결책은 위치 매핑 결과가

인 것입니다. 왜 geo_point 나의 매핑

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

어떤 생각을 무시 :

그리고 물론

location: { 
    type: "string" 
    }, 
위치 필드는 문자열로 인덱싱?

감사합니다.

+0

이 이상해 : 당신이 위치를 지원하는 빈 타이어 응용 프로그램 (추가 정보에 명령을 참조)를 생성 할 수 있을까?를 시도했지만 매핑이 올바르게 저장되었습니다. 또한 Gemfile에서 Github의 버전을 사용할 수 있습니까? – karmi

+1

Arrgh !!! 나는 타입을 잘못 입력했다! geo_type이 아니지만 geo_point ... 이상하게도 elasticsearch에서 오류가 발생하지 않았지만 업데이트 후 (0.19.10까지) elasticsearch에서 오류가 발생했습니다 ... 도움을 주셔서 감사 드리며이 "오타 질문"에 대해 사과드립니다 :) – Tricote

+0

Cool ! 다행히 해결되었습니다. – karmi

답변

2

location 색인 유형을 잘못 입력했습니다.

당신은 geo_type 대신 geo_point을 사용 :

indexes :location, type: 'geo_point', as: 'location'