【问题标题】:Alternative syntax for ElasticSearch vs ThinkingSphinxElasticSearch 与 ThinkingSphinx 的替代语法
【发布时间】:2013-03-15 00:00:52
【问题描述】:

请看下面的代码,它是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}

【问题讨论】:

    标签: ruby-on-rails-3.2 elasticsearch thinking-sphinx tire


    【解决方案1】:

    使用string 类型来定义数组的映射,正如documentation 所建议的那样:

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

    请注意,您可以使用 as 选项在 mapping 块中定义 JSON 序列化:

    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-06-04
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-05-04
      • 1970-01-01
      • 1970-01-01
      • 2013-07-09
      • 1970-01-01
      相关资源
      最近更新 更多