Class: Chewy::Search::Parameters::Filter

Inherits:
Storage
  • Object
show all
Includes:
QueryStorage
Defined in:
lib/chewy/search/parameters/filter.rb

Overview

This parameter storage doesn’t have its own parameter at the ES request body. Instead, it is embedded to the root ‘bool` query of the `query` request parameter. Some additional query reduction is performed in case of only several `must` filters presence.

Examples:

scope = PlacesIndex.filter(term: {name: 'Moscow'})
# => <PlacesIndex::Query {..., :body=>{:query=>{:bool=>{:filter=>{:term=>{:name=>"Moscow"}}}}}}>
scope.query(match: {name: 'London'})
# => <PlacesIndex::Query {..., :body=>{:query=>{:bool=>{
#      :must=>{:match=>{:name=>"London"}},
#      :filter=>{:term=>{:name=>"Moscow"}}}}}}>

See Also:

Instance Attribute Summary

Attributes inherited from Storage

#value

Instance Method Summary collapse

Methods included from QueryStorage

#and, #merge!, #minimum_should_match, #must, #must_not, #not, #or, #should, #update!

Methods inherited from Storage

#==, #initialize, #merge!, #replace!, #update!

Constructor Details

This class inherits a constructor from Chewy::Search::Parameters::Storage

Instance Method Details

#render{Symbol => Hash}

Even more reduction added here, we don’t need to wrap with ‘bool` query consists on `must` only.

Returns:

  • ({Symbol => Hash})

See Also:



29
30
31
32
# File 'lib/chewy/search/parameters/filter.rb', line 29

def render
  rendered_bool = filter_query(value.query)
  {self.class.param_name => rendered_bool} if rendered_bool.present?
end