Method: Chewy::Search::QueryProxy#must_not

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

#must_not(query_hash) ⇒ Chewy::Search::Request #must_not { ... } ⇒ Chewy::Search::Request

Executes Parameters::QueryStorage#must_not in the scope of newly created request object.

Overloads:

  • #must_not(query_hash) ⇒ Chewy::Search::Request

    If pure hash is passed it is added to must_not array of the bool query.

    Examples:

    PlacesIndex.query.must_not(match: {name: 'Moscow'}).query.must_not(match: {name: 'London'})
    # => <PlacesIndex::Query {..., :body=>{:query=>{:bool=>{
    #      :must_not=>[{:match=>{:name=>"Moscow"}}, {:match=>{:name=>"London"}}]}}}}>

    Parameters:

    • query_hash (Hash)

      pure query hash

    See Also:

  • #must_not { ... } ⇒ Chewy::Search::Request

    If block is passed instead of a pure hash, `elasticsearch-dsl" gem will be used to process it.

    Examples:

    PlacesIndex.query.must_not { match name: 'Moscow' }.query.must_not { match name: 'London' }
    # => <PlacesIndex::Query {..., :body=>{:query=>{:bool=>{
    #      :must_not=>[{:match=>{:name=>"Moscow"}}, {:match=>{:name=>"London"}}]}}}}>

    Yields:

    • the block is processed by elasticsearch-dsl gem

    See Also:

Returns:

See Also:



102
103
104
105
106
107
108
# File 'lib/chewy/search/query_proxy.rb', line 102

%i[must should must_not].each do |method|
  define_method method do |query_hash = nil, &block|
    raise ArgumentError, "Please provide a parameter or a block to `#{method}`" unless query_hash || block

    @request.send(:modify, @parameter_name) { send(method, block || query_hash) }
  end
end