2

I just started on the Chewy gem, looks like a great idea, but I'm unable to get it working properly with even a super basic query.

I have indexed my Lead model as LeadsIndex. Here I have a query that works:

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"}}>

But when I try to search for that very record, it shows no results:

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

Am I doing something wrong?

Sergio Tulentsev
  • 226,338
  • 43
  • 373
  • 367
hash12
  • 181
  • 1
  • 9

1 Answers1

1

You can either match phrase:

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

or else chain the queries together:

LeadsIndex.filter { name == "Victoria" }.filter { name == "Roob" }.first
CMGS
  • 71
  • 1
  • 5