From 10c36ad530f135d0e59cb35c12c45d2c895bf444 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Honza=20Kr=C3=A1l?= Date: Mon, 18 May 2015 15:50:35 +0200 Subject: [PATCH] Make search_exists consistent with other _exists APIs Fixes #230 Thanks ncrocfer for the report! --- elasticsearch/client/__init__.py | 9 ++++++--- elasticsearch/transport.py | 2 +- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/elasticsearch/client/__init__.py b/elasticsearch/client/__init__.py index 772303bb..625dbf7f 100644 --- a/elasticsearch/client/__init__.py +++ b/elasticsearch/client/__init__.py @@ -1244,9 +1244,12 @@ class Elasticsearch(object): :arg q: Query in the Lucene query string syntax :arg routing: Specific routing value """ - _, data = self.transport.perform_request('POST', _make_path(index, - doc_type, '_search', 'exists'), params=params, body=body) - return data + try: + self.transport.perform_request('POST', _make_path(index, + doc_type, '_search', 'exists'), params=params, body=body) + except NotFoundError: + return False + return True @query_params('allow_no_indices', 'expand_wildcards', 'fields', 'ignore_unavailable', 'level') diff --git a/elasticsearch/transport.py b/elasticsearch/transport.py index 6f82eb66..9f553200 100644 --- a/elasticsearch/transport.py +++ b/elasticsearch/transport.py @@ -273,7 +273,7 @@ class Transport(object): body = self.serializer.dumps(body) # some clients or environments don't support sending GET with body - if method == 'GET' and self.send_get_body_as != 'GET': + if method in ('HEAD', 'GET') and self.send_get_body_as != 'GET': # send it as post instead if self.send_get_body_as == 'POST': method = 'POST'