Skip to content

search_exists throws an exception #230

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
ncrocfer opened this issue May 7, 2015 · 4 comments
Closed

search_exists throws an exception #230

ncrocfer opened this issue May 7, 2015 · 4 comments

Comments

@ncrocfer
Copy link

ncrocfer commented May 7, 2015

Hello,

I'm using the search_exists API to determine if a document exists based on one field, but the client throws an exception when there is no matching.

For example, I know this document exists :

>>> es = Elasticsearch(...)
>>> es.search_exists('my_index', 'my_type', params={'q': 'my_field:foo'})
{u'exists': True}

But when a document doesn't exist :

>>> es.search_exists('my_index', 'my_type', params={'q': 'my_field:bar'})
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/local/lib/python2.7/dist-packages/elasticsearch/client/utils.py", line 68, in _wrapped
    return func(*args, params=params, **kwargs)
  File "/usr/local/lib/python2.7/dist-packages/elasticsearch/client/__init__.py", line 1238, in search_exists
    doc_type, '_search', 'exists'), params=params, body=body)
  File "/usr/local/lib/python2.7/dist-packages/elasticsearch/transport.py", line 307, in perform_request
    status, headers, data = connection.perform_request(method, url, params, body, ignore=ignore, timeout=timeout)
  File "/usr/local/lib/python2.7/dist-packages/elasticsearch/connection/http_urllib3.py", line 86, in perform_request
    self._raise_error(response.status, raw_data)
  File "/usr/local/lib/python2.7/dist-packages/elasticsearch/connection/base.py", line 102, in _raise_error
    raise HTTP_EXCEPTIONS.get(status_code, TransportError)(status_code, error_message, additional_info)
elasticsearch.exceptions.NotFoundError: TransportError(404, u'{"exists":false}')

Did I forget something? Thank you.

@honzakral
Copy link
Contributor

You didn't forget anything. Currently we reply with True/False for all of the *_exists APIs so it is natural to expect it from this one too.

The reason (ehm, rationalization) why this API is different is that it uses a POST http method (bacause it needs body) and not HEAD like all the others. We will most likely change it to be consistent but we need to synchronize with the other language clients for ES.

Sorry for the delay and the confusion.

@ncrocfer
Copy link
Author

Ok, no problem :) Thank you for your answer.

@honzakral
Copy link
Contributor

Fixed in the python client, waiting for elasticsearch to catch up as well - elastic/elasticsearch#11204

@ncrocfer
Copy link
Author

Great ! Thank you @honzakral 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants