Browse files

Revise delete_by_query().

* Support multiple indices and doctypes.
* Support passing a string query as the ``query`` arg. Since this is a required arg, we should act like the search() method, taking body string and JSON queries. Passing the ``q`` kwarg explicitly is now deprecated.
  • Loading branch information...
1 parent 26a812f commit 943e9e67c6a2b515411652ddf50386fbaa85b106 @erikrose erikrose committed Mar 22, 2013
Showing with 19 additions and 5 deletions.
  1. +3 −0 docs/source/changelog.rst
  2. +16 −5 pyelasticsearch/
@@ -4,6 +4,9 @@ Changelog
v0.5 (unreleased)
+* Support multiple indices and doctypes in ``delete_by_query()``. Accept both
+ string and JSON queries in the ``query`` arg, just as ``search()`` does.
+ Passing the ``q`` arg explicitly is now deprecated.
* Add ``multi_get`` support.
* Remove the internal, undocumented ``from_python`` method. django-haystack
users will need to upgrade to a newer version that avoids using it.
@@ -412,17 +412,28 @@ def delete_by_query(self, index, doc_type, query, query_params=None):
Delete typed JSON documents from a specific index based on query.
- :arg index: The name of the index from which to delete
- :arg doc_type: The type of document to delete
- :arg query: A dict of query DSL selecting the documents to delete
+ :arg index: An index or iterable thereof from which to delete
+ :arg doc_type: The type of document or iterable thereof to delete
+ :arg query: A dictionary that will convert to ES's query DSL or a
+ string that will serve as a textual query to be passed as the ``q``
+ query string parameter. (Passing the ``q`` kwarg yourself is
+ deprecated.)
See `ES's delete-by-query API`_ for more detail.
.. _`ES's delete-by-query API`:
- return self.send_request('DELETE', [index, doc_type, '_query'], query,
- query_params=query_params)
+ if isinstance(query, string_types) and 'q' not in query_params:
+ query_params['q'] = query
+ body = ''
+ else:
+ body = query
+ return self.send_request(
+ [self._concat(index), self._concat(doc_type), '_query'],
+ body,
+ query_params=query_params)
@es_kwargs('realtime', 'fields', 'routing', 'preference', 'refresh')
def get(self, index, doc_type, id, query_params=None):

0 comments on commit 943e9e6

Please sign in to comment.