-->

使用elasticsearch通过与空白标记过滤(using elasticsearch to fi

2019-07-30 19:46发布

我使用与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:“世界你好”]}。 那么下面的查询做工精细:

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

Answer 1:

问题解决在:

使用keyword分析仪为tags_array属性:

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


文章来源: using elasticsearch to filter through tags with whitespace