Search code examples
pythonelasticsearchelasticsearch-py

Error while deleting a index in Elastic search


I am working with Elastic search Python API. I created a index called "sample". But, facing an exception while trying to delete the same. Below is my approach.

Elastic search instance,

es = Elasticsearch("abc.def.ghi.jkl:9300")

Checking whether the index exists

es.indices.exists(index="sample")
True

Trying to delete the index,

es.indices.delete(index="sample") 

Error:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/Users/adaggula/anaconda/lib/python2.7/site-packages/elasticsearch/client/utils.py", line 69, in _wrapped
    return func(*args, params=params, **kwargs)
  File "/Users/adaggula/anaconda/lib/python2.7/site-packages/elasticsearch/client/indices.py", line 200, in delete
    params=params)
  File "/Users/adaggula/anaconda/lib/python2.7/site-packages/elasticsearch/transport.py", line 353, in perform_request
    data = self.deserializer.loads(data, headers.get('content-type'))
  File "/Users/adaggula/anaconda/lib/python2.7/site-packages/elasticsearch/serializer.py", line 76, in loads
    return deserializer.loads(s)
  File "/Users/adaggula/anaconda/lib/python2.7/site-packages/elasticsearch/serializer.py", line 40, in loads
    raise SerializationError(s, e)
elasticsearch.exceptions.SerializationError: (u'This is not a HTTP port', ValueError('No JSON object could be decoded',))

Donno why this error causing.


Solution

  • You need to use the port 9200, which is dedicated to HTTP communications not 9300 which is dedicated to TCP communications

    es = Elasticsearch("abc.def.ghi.jkl:9200")
                                         ^
                                         |
                                    change this