问题
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