您的问题很可能是由于对该status
字段使用默认映射而引起的,该映射会将其标记化-小写,拆分为单词等。
比较这两个:
http://localhost:9200/myindex/_analyze?text=Text1&analyzer=standard
http://localhost:9200/myindex/_analyze?text=Text1&analyzer=keyword
您的解决方案是在映射中使用keyword
分析器(或将字段设置为not_analyzed
)。如果该字段不是“枚举”类型的数据,则可以使用多字段功能。
有效的Ruby版本如下所示:
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
注意:在没有提供索引映射,示例数据等的情况下,极不可能(在这种情况下为例外)提供合理的建议。