开发者社区> 问答> 正文

python 处理ES时 删除已有的索引后仍报该索引存在?报错

在python脚本下对获取到的json 内容存入es中,已经在try部分删除该索引名称的内容,然后再重新创建,但编译会提示该索引已经存在,进而无法往es中存入数据。

代码如下:

conn=ES(['******'],bulk_size = 10000,timeout = 20)

    try:
        conn.indices.delete_index('aa')
    except:
        pass
    conn.indices.create_index('aa')

报错信息:

Exception in thread Thread-7:
Traceback (most recent call last):
  File "C:\Anaconda\lib\threading.py", line 810, in __bootstrap_inner
    self.run()
  File "E:\xxWorkspace\BaiduMap\get_pois.py", line 61, in run
    Data2ES(res)
  File "E:\xxWorkspace\BaiduMap\get_pois.py", line 172, in Data2ES
    conn.indices.create_index('aa')
  File "C:\Anaconda\lib\site-packages\pyes\managers.py", line 165, in create_index
    return self.conn._send_request('PUT', index, settings)
  File "C:\Anaconda\lib\site-packages\pyes\es.py", line 486, in _send_request
    raise_if_error(response.status, decoded)
  File "C:\Anaconda\lib\site-packages\pyes\convert_errors.py", line 85, in raise_if_error
    raise excClass(msg, status, result, request)
IndexAlreadyExistsException: [aa] already exists]; 

有经验的童鞋请帮忙看下。多谢

展开
收起
爱吃鱼的程序员 2020-06-09 11:24:30 634 0
1 条回答
写回答
取消 提交回答
  • https://developer.aliyun.com/profile/5yerqm5bn5yqg?spm=a2c6h.12873639.0.0.6eae304abcjaIB

    不要try,直接写

    conn.indices.delete_index('aa')

    conn.indices.create_index('aa')

    你看看这个delete_index出错了吗

    2020-06-09 11:24:46
    赞同 展开评论 打赏
问答排行榜
最热
最新

相关电子书

更多
From Python Scikit-Learn to Sc 立即下载
Data Pre-Processing in Python: 立即下载
双剑合璧-Python和大数据计算平台的结合 立即下载