Skip to content
Permalink
Browse files

Add test and doc for Search.exclude() in PR #530 (#596)

  • Loading branch information...
nonbeing authored and HonzaKral committed Feb 18, 2017
1 parent c1bec1e commit 6dabbb9e6c3b35f01a996c239e0628cf281b5d46
Showing with 29 additions and 2 deletions.
  1. +1 −1 README
  2. +8 −1 docs/search_dsl.rst
  3. +20 −0 test_elasticsearch_dsl/test_search.py
2 README
@@ -230,7 +230,7 @@ To install all of the dependencies necessary for development, run:

.. code:: bash

$ pip install -e .[develop]
$ pip install -e '.[develop]'

To run all of the tests for ``elasticsearch-dsl-py``, run:

@@ -202,10 +202,17 @@ Behind the scenes this will produce a ``Bool`` query and place the specified
s = s.query('bool', filter=[Q('terms', tags=['search', 'python'])])
If you want to use the post_filter element for faceted navigation, use the
``.post_filter()`` method.

You can also ``exclude()`` items from your query like this:

.. code:: python
s = Search()
s = s.exclude('terms', tags=['search', 'python'])
which is shorthand for: ``s = s.query('bool', filter=[~Q('terms', tags=['search', 'python'])])``

Aggregations
~~~~~~~~~~~~
@@ -485,3 +485,23 @@ def test_suggest():
}
}
} == s.to_dict()

def test_exclude():
s = search.Search()
s = s.exclude('match', title='python')

assert {
'query': {
'bool': {
'filter': [{
'bool': {
'must_not': [{
'match': {
'title': 'python'
}
}]
}
}]
}
}
} == s.to_dict()

0 comments on commit 6dabbb9

Please sign in to comment.
You can’t perform that action at this time.