using elasticsearch to filter through tags with whitespace

家住魔仙堡 提交于 2019-12-21 06:06:52

问题


I am using tire (https://github.com/karmi/tire) with mongoid. Here is my model definition:

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

Say I have a document {tags_array: ["hello world"]}. Then the following queries work fine:

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"] }

But the following doesn't return any results:

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

What should I do to make it work?

Edit: here's a small piece of code to test: http://pastebin.com/n1rUtK3e


回答1:


Issue solved at :

Use the keyword analyzer for the tags_array property:

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


来源:https://stackoverflow.com/questions/11822019/using-elasticsearch-to-filter-through-tags-with-whitespace

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!