2

我刚开始使用 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

难道我做错了什么?

4

1 回答 1

1

您可以匹配短语:

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

或者将查询链接在一起:

LeadsIndex.filter { name == "Victoria" }.filter { name == "Roob" }.first
于 2017-02-28T16:32:41.930 回答