Method: Chewy::Search::Request#and

Defined in:
lib/chewy/search/request.rb

#and(other) ⇒ Chewy::Search::Request

Takes query, filter, post_filter from the passed scope and performs QueryProxy#and operation for each of them. Unlike merge, every other parameter is kept unmerged (values from the first scope are used in the result scope).

Examples:

scope1 = PlacesIndex.filter(term: {name: 'Moscow'}).query(match: {name: 'London'})
scope2 = PlacesIndex.filter.not(term: {name: 'Berlin'}).query(match: {name: 'Washington'})
scope1.and(scope2)
# => <PlacesIndex::Query {..., :body=>{:query=>{:bool=>{
#      :must=>[{:match=>{:name=>"London"}}, {:match=>{:name=>"Washington"}}],
#      :filter=>{
#        :bool=>{:must=>[{:term=>{:name=>"Moscow"}}, {:bool=>{:must_not=>{:term=>{:name=>"Berlin"}}}}]}
#      }
#    }}}}>

Parameters:

Returns:

See Also:



814
815
816
817
818
819
820
# File 'lib/chewy/search/request.rb', line 814

i[and or not].each do |name|
  define_method name do |other|
    i[query filter post_filter].inject(self) do |scope, parameter_name|
      scope.send(parameter_name).send(name, other.parameters[parameter_name].value)
    end
  end
end