I'm creating an Elasticsearch index using Python API like this:
from elasticsearch import Elasticsearch
es = Elasticsearch()
index_body = {"mappings": {".percolator": {"properties": {"message": {"type": "string", "analyzer": "english"}}}}}
# Creates the index if it doesn't exist
if not es.indices.exists('test'):
es.indices.create(index='test', body=index_body)
print es.exists(index='test', id='1')
The index is created successfully, but when I check for the existence of a document inside the index it fails with this error:
Traceback (most recent call last):
File "main.py", line 12, in <module>
print es.exists(index='test', id='1')
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 282, in exists
self.transport.perform_request('HEAD', _make_path(index, doc_type, id), params=params)
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.TransportError: TransportError(503, u'')
If I run this script a second time, with the index already created it works just fine. Does anyone have an idea of what could be going wrong?
/var/log/elasticsearch/<nodename>.log
, it could contain more information.503
is usually indicating a problem with the cluster in some way. Maybe the index is not yet created (in the cluster) when you already send the next request? Does it work if you wait a second before tryinges.exists
?time.sleep(1)
beforees.exists(index='test', id='1')
it works perfectly. No information in the log file though.