【问题标题】:using elasticsearch to filter through tags with whitespace使用 elasticsearch 过滤带有空格的标签
【发布时间】:2012-08-03 01:18:25
【问题描述】:

我正在使用带有 mongoid 的轮胎 (https://github.com/karmi/tire)。这是我的模型定义:

class SomethingWithTag
  include Mongoid::Document
  include Mongoid::Timestamps
  field :tags_array, type: Array

  include Tire::Model::Search
  include Tire::Model::Callbacks
  mapping do
      indexes :tags_array, type: :array, index: :not_analyzed
  end
end

假设我有一个文档 {tags_array: ["hello world"]}。然后以下查询可以正常工作:

SomethingWithTag.tire.search { filter :terms, :tags_array => ["hello"] }
SomethingWithTag.tire.search { filter :terms, :tags_array => ["world"] }
SomethingWithTag.tire.search { filter :terms, :tags_array => ["hello", "world"] }

但以下不返回任何结果:

SomethingWithTag.tire.search { filter :terms, :tags_array => ["hello world"] }

我应该怎么做才能让它工作?

编辑:这里有一小段代码要测试:http://pastebin.com/n1rUtK3e

【问题讨论】:

标签: ruby mongoid search-engine elasticsearch tire


【解决方案1】:

问题已解决:

tags_array 属性使用keyword 分析器:

class SomethingWithTag
  # ...
  mapping do
    indexes :tags_array, analyzer: 'keyword'
  end
end

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-11-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多