在弹性搜索中删除索引时出错

时间:2016-07-02 09:20:03

标签: python elasticsearch elasticsearch-py

我正在使用Elastic search Python API。我创建了一个名为“sample”的索引。但是,在尝试删除同样的情况时面临异常。以下是我的方法。

弹性搜索实例,

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

检查索引是否存在

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

尝试删除索引

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

错误:

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为何导致此错误。

1 个答案:

答案 0 :(得分:2)

您需要使用专用于HTTP通信的端口9200,而不是专用于TCP通信的9300

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