如果这是非常基本的,请原谅我,但我有 Python 2.7 和 Elasticsearch 2.1.1,我只是想使用删除索引
es.delete(index='researchtest', doc_type='test')
但这给了我
return func(*args, params=params, **kwargs)
TypeError: delete() takes at least 4 arguments (4 given)
我也试过了
es.delete_by_query(index='researchtest', doc_type='test',body='{"query":{"match_all":{}}}')
但我明白了
AttributeError: 'Elasticsearch' object has no attribute 'delete_by_query'
知道为什么吗? python 的 2.1.1 的 api 是否已更改?
最佳答案
对于 ES 8+ 使用:
from elasticsearch import Elasticsearch
es = Elasticsearch()
es.options(ignore_status=[400,404]).indices.delete(index='test-index')
对于旧版本,请使用此表示法:
from elasticsearch import Elasticsearch
es = Elasticsearch()
es.indices.delete(index='test-index', ignore=[400, 404])
关于python - Elasticsearch : How to delete an Index using python,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35134162/