2013-03-15 56 views
0

請對下面的代碼一看,它爲thinking sphinx爲ElasticSearch替代語法VS ThinkingSphinx

indexes owned_tags.name, :as => :owned_tag_names 
has owned_tags.id, :as => :owned_tag_ids, :facet => true 

正常索引的語句可以在任何一個導向會是什麼語法有ElasticSearch相同指數?

我試過了。

tire.mapping do 
    indexes :owned_tag_names, type: 'array', analyzer: :ngram_analyzer, index_name: 'tag' 
    indexes :owned_tag_ids, type: 'array' 
end 

def to_indexed_json 
{ 
    owned_tag_names: owned_tags.collect(&:name), 
    owned_tag_ids: owned_tags.collect(&:id) 
}.to_json 
end 

和它給我的錯誤:

400 : {"error":"MapperParsingException[mapping [user]]; nested: MapperParsingException[No handler for type [array] declared on field [owned_tag_ids]]; ","status":400} 

回答

1

使用string類型definining映射陣列,作爲documentation提示:

tire.mapping do 
    indexes :owned_tag_names, type: 'string', analyzer: :ngram_analyzer, index_name: 'tag' 
    indexes :owned_tag_ids, type: 'string' 
end 

注意,你可以定義mapping塊中的JSON序列號與as選項:

tire.mapping do 
    indexes :owned_tag_names, 
      type: 'array', 
      analyzer: :ngram_analyzer, 
      index_name: 'tag', 
      as: proc { owned_tags.collect(&:name) } 

    indexes :owned_tag_ids, 
      type: 'array', 
      as: proc { owned_tags.collect(&:id) } 
end