Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions django_elasticsearch/query.py
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,12 @@ def make_search_body(self):
if is_nested and isinstance(value, Model):
value = value.id

if operator == 'contains':
if operator == 'in':
nested_update(filters,
{'query': {'filtered': {"filter": {'terms': { field_name: value }}}}})
if len(filters['query']['filtered']["filter"]['terms'].items()) > 1:
raise NotImplementedError("multi_terms is not implemented.")
elif operator == 'contains':
nested_update(filters,
{'query': {'match': {field_name: {'query': value}}}})
if len(filters['query']['match'].items()) > 1:
Expand Down Expand Up @@ -321,7 +326,7 @@ def filter(self, **kwargs):
return clone

def sanitize_lookup(self, lookup):
valid_operators = ['exact', 'not', 'should', 'range', 'gt', 'lt', 'gte', 'lte', 'contains', 'isnull']
valid_operators = ['exact', 'not', 'should', 'range', 'gt', 'lt', 'gte', 'lte', 'contains', 'in', 'isnull']
words = lookup.split('__')
fields = [word for word in words if word not in valid_operators]
# this is also django's default lookup type
Expand Down
2 changes: 1 addition & 1 deletion readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,7 @@ Note that es.search automatically add the default facets set on the model to the
* **es.queryset.order_by**(**kwargs)

* **es.queryset.filter**(**kwargs)
Accepted lookups are: __exact, __should, __contains, __gt, __gte, __lt, __lte, __range
Accepted lookups are: __exact, __should, __contains, __in, __gt, __gte, __lt, __lte, __range
Just like in django, the default lookup is __exact.
See the [bool query](http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/query-dsl-bool-query.html) for a difference between __exact (which maps to 'must') and __should.

Expand Down