使用elasticsearch来过滤带有空格的标签

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

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

问题解决于:

keyword分析器用于tags_array属性:

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