elasticsearch轮胎宝石完全匹配

时间:2013-09-24 21:24:23

标签: ruby elasticsearch tire

我目前正在使用Tire来访问我的ES数据但是我无法让它进行完全匹配,例如

User.search :per_page => 10 do 
 query do
    boolean do
       must { match :first_name, 'tom'}
       must { match :last_name, 'smith'}
       end
   end
end

然而,当我希望它只匹配汤姆时,它会返回tom,tomas,tommy和tomiena等名字。

2 个答案:

答案 0 :(得分:1)

尝试使用match_phrase查询

User.search :per_page => 10 do 
 query do
    boolean do
       must { match :first_name, 'tom', :type => :phrase}
       must { match :last_name, 'smith', :type => :phrase}
       end
   end
end

答案 1 :(得分:0)

您可以尝试使用 query_string 查询:

User.search :per_page => 10 do 
 query do
    boolean do
       must { string 'first_name:tom'}
       must { string 'last_name:smith'}
       end
   end
end

如果这不起作用,则意味着您必须检查分析仪。