Skip to content

Instantly share code, notes, and snippets.

@edipofederle
Created July 11, 2015 20:43
Show Gist options
  • Save edipofederle/8deb9b8781f9db6fc599 to your computer and use it in GitHub Desktop.
Save edipofederle/8deb9b8781f9db6fc599 to your computer and use it in GitHub Desktop.
>> result = ClientIndex.filter {company_id == 2364}.limit(2)
=> #<Chewy::Query:0x0000010648a920 @options={}, @index=ClientIndex, @types=["person_client"], @criteria=#<Chewy::Query::Criteria:0x0000010648a8a8 @options={:query_mode=>:must, :filter_mode=>:and, :post_filter_mode=>:and}, @queries=[], @filters=[{:term=>{"company_id"=>2364}}], @post_filters=[], @sort=[], @fields=[], @types=[], @scores=[], @request_options={:size=>2}, @facets={}, @aggregations={}, @suggest={}>, @_request=nil, @_response=nil, @_results=nil, @_collection=nil>
>> result.map {|c| c.name }
ClientIndex Search (8.1ms) {:body=>{:query=>{:filtered=>{:query=>{:match_all=>{}}, :filter=>{:term=>{"company_id"=>2364}}}}, :size=>2}, :index=>"client", :type=>["person_client"]}
=> ["teste 5", "teste 1"]
>> search = result.filter {name == "ana"}
=> #<Chewy::Query:0x00000106462b50 @options={}, @index=ClientIndex, @types=["person_client"], @criteria=#<Chewy::Query::Criteria:0x00000106462ab0 @options={:query_mode=>:must, :filter_mode=>:and, :post_filter_mode=>:and}, @queries=[], @filters=[{:term=>{"company_id"=>2364}}, {:term=>{"name"=>"ana"}}], @post_filters=[], @sort=[], @fields=[], @types=[], @scores=[], @request_options={:size=>2}, @facets={}, @aggregations={}, @suggest={}>, @_request=nil, @_response=nil, @_results=nil, @_collection=nil>
>> search.first.name
ClientIndex Search (7.2ms) {:body=>{:query=>{:filtered=>{:query=>{:match_all=>{}}, :filter=>{:and=>[{:term=>{"company_id"=>2364}}, {:term=>{"name"=>"ana"}}]}}}, :size=>2}, :index=>"client", :type=>["person_client"]}
=> "Ana Julia"
>>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment