【问题标题】:How do you get the Chewy gem to filter results?你如何获得 Chewy gem 来过滤结果?
【发布时间】:2017-03-01 00:44:09
【问题描述】:

我刚开始使用 Chewy gem,看起来是个好主意,但即使是超级基本的查询,我也无法让它正常工作。

我已将我的潜在客户模型索引为 LeadsIndex。 这里我有一个有效的查询:

irb(main):068:0> LeadsIndex.filter.first
  LeadsIndex Search (8.9ms) {:body=>{}, :index=>["leads"], :type=>[]}
=> #<LeadsIndex::Lead:0x007ff76324cbf8 @attributes={"id"=>"14", "name"=>"Victoria Roob", "_score"=>1.0, "_explanation"=>nil}, 
                                       @_data={"_index"=>"leads", "_type"=>"lead", "_id"=>"14", "_score"=>1.0, "_source"=>{"name"=>"Victoria Roob"}}>

但是当我尝试搜索该记录时,它没有显示任何结果:

irb(main):071:0> LeadsIndex.filter { name == "Victoria Roob" }.first
  LeadsIndex Search (7.4ms) {:body=>{:query=>{:filtered=>{:query=>{:match_all=>{}}, :filter=>{:term=>{"name"=>"Victoria Roob"}}}}}, :index=>["leads"], :type=>[]}
=> nil

我是不是做错了什么?

【问题讨论】:

    标签: ruby-on-rails ruby chewy-gem


    【解决方案1】:

    你可以匹配词组:

    LeadsIndex.query(match_phrase: {name: "Victoria Root"}).first
    

    或者将查询链接在一起:

    LeadsIndex.filter { name == "Victoria" }.filter { name == "Roob" }.first
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-08-14
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-10-05
      • 1970-01-01
      相关资源
      最近更新 更多