tire terms filter not working

假如想象 提交于 2019-12-08 19:20:32

Your issue is most probably being caused by using the default mappings for the status field, which would tokenize it -- downcase, split into words, etc.

Compare these two:

http://localhost:9200/myindex/_analyze?text=Text1&analyzer=standard

http://localhost:9200/myindex/_analyze?text=Text1&analyzer=keyword

The solution in your case is to use the keyword analyzer (or set the field to not_analyzed) in your mapping. When the field would not be an “enum” type of data, you could use the multi-field feature.

A working Ruby version would look like this:

require 'tire'

Tire.index('myindex') do
  delete
  create mappings: {
    document: {
      properties: {
        status: { type: 'string', analyzer: 'keyword' }
      }
    }
  }

  store status: 'Test1'
  store status: 'Test2'

  refresh
end

search = Tire.search 'myindex' do
  query do
    filtered do
      query { all }
      filter :terms, status: ['Test1']
    end
  end
end

puts search.results.to_a.inspect

Note: It's rarely possible -- this case being an exception -- to offer reasonable advice when no index mappings, example data, etc. are provided.

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