ruby-on-rails-3.2 - ElasticSearch与ThinkingSphinx的替代语法

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

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

最佳答案

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

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

注意,您可以使用mapping选项在as块中定义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

关于ruby-on-rails-3.2 - ElasticSearch与ThinkingSphinx的替代语法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15422443/

相关文章:

elasticsearch - Elasticsearch 1.5.2部署问题

mysql - Thinking Sphinx 多个表单字段

ruby-on-rails - 按日期范围过滤 Sphinx 搜索结果

ruby-on-rails - Assets 管道未导入 ERB

elasticsearch - ElasticSearch-搜索范围内的任何嵌套字段

elasticsearch - Logstash输入->某些属性或可参数化文件中的JDBC?

mysql - 检测邮寄地址相似度

ruby-on-rails - 在 strip 结帐之前验证表单

ruby-on-rails - 强参数允许嵌套属性的所有属性

ruby-on-rails - 如何为 Rails 3.2 中的每个请求重新加载 gem?