0

请看下面的代码,它是正常的索引语句thinking sphinx

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}
4

1 回答 1

1

正如文档所建议的,使用该string类型来定义数组的映射:

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
于 2013-03-15T08:08:49.310 回答