【问题标题】:elasticsearch tire gem exact matchelasticsearch轮胎宝石完全匹配
【发布时间】:2013-12-02 15:37:15
【问题描述】:

我目前正在使用 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 时,它会返回 tom、tomas、tommy 和 tomiena 的名字。

【问题讨论】:

  • 这取决于使用的分析仪。你的mapping 是什么?

标签: ruby elasticsearch tire


【解决方案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

【讨论】:

  • 我得到未定义的方法 match_phrase 用于 Tire::Search::Query。
  • @jeremywoertink 您使用哪个版本的轮胎?
  • 我有版本 0.6.1 正在运行。
  • 抱歉耽搁了,您可以尝试匹配:type => phrase作为选项。如果这有效,请告诉我。我会相应地更新答案。我只是根据弹性搜索选项给出了答案。我以为轮胎会使用相同的选项。
  • 是的,成功了!更新的答案对我来说很好。谢谢:)
【解决方案2】:

您可以尝试使用 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

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

【讨论】:

    猜你喜欢
    • 2012-08-24
    • 1970-01-01
    • 1970-01-01
    • 2012-06-04
    • 2012-01-25
    • 1970-01-01
    • 1970-01-01
    • 2013-10-20
    • 1970-01-01
    相关资源
    最近更新 更多