python和弹性搜索更新错误

时间:2015-12-04 10:22:04

标签: python elasticsearch flask

今天我将弹性搜索从1.6更新到2.1,因为1.6是易受攻击的版本,在此更新后我的网站无法正常工作,给出此错误:

Traceback (most recent call last):
  File "manage.py", line 8, in <module>
    from app import app, db
  File "/opt/project/app/__init__.py", line 30, in <module>
    es.create_index(app.config['ELASTICSEARCH_INDEX'])
  File "/usr/local/lib/python2.7/dist-packages/pyelasticsearch/client.py", line 93, in decorate
    return func(*args, query_params=query_params, **kwargs)
  File "/usr/local/lib/python2.7/dist-packages/pyelasticsearch/client.py", line 1033, in create_index
    query_params=query_params)
  File "/usr/local/lib/python2.7/dist-packages/pyelasticsearch/client.py", line 285, in send_request
    self._raise_exception(status, error_message)
  File "/usr/local/lib/python2.7/dist-packages/pyelasticsearch/client.py", line 299, in _raise_exception
    raise error_class(status, error_message)
pyelasticsearch.exceptions.ElasticHttpError: (400, u'index_already_exists_exception')
make: *** [run] Error 1

代码是这样的:

redis = Redis()

es = ElasticSearch(app.config['ELASTICSEARCH_URI'])
try:
    es.create_index(app.config['ELASTICSEARCH_INDEX'])
except IndexAlreadyExistsError, e:
    pass

哪里错了?这个新版本有什么新东西?

2 个答案:

答案 0 :(得分:0)

您收到以下错误:index_already_exists_exception

这意味着您正在尝试创建已存在的索引。第二次运行程序时,您需要先delete your index或仅在不存在的情况下创建它。

答案 1 :(得分:0)

您已使用IndexAlreadyExistsError处理了异常。尝试使用TransportError来处理异常。

您还可以添加以下支票:

exist = es.indices.exists(index_name)
if not exist:
    es.create_index(app.config['ELASTICSEARCH_INDEX'])