我有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有变化吗?
https://elasticsearch-py.readthedocs.org/en/master/api.html#elasticsearch.client.IndicesClient.delete
5条答案
按热度按时间ukdjmx9f1#
对于ES 8+用途:
字符串
对于旧版本,请使用此表示法:
型
bvjxkvbb2#
如果你有一个文档对象(模型),并且你正在使用elasticsearch-search,特别是在Python-3.X中,你可以直接调用模型
_index
属性的delete
方法。字符串
正如文档中所述:
_index
属性也是load_mappings方法的所在地,该方法将从elasticsearch更新Index上的Map。如果您使用动态Map并希望类知道这些字段(例如,如果您希望Date字段正确(反)序列化),则这非常有用:型
pdtvr36n3#
由于在API方法中传递传输选项在Elasticsearch python客户端8+中已被弃用,因此指定应忽略的HTTP状态代码的方法(例如,在目标索引不存在的情况下防止出错)现在应使用
Elasticsearch.options()
:字符串
(see文档)。
fxnxkyjh4#
如果您使用的是elasticsearch-search,请使用
字符串
wbrvyc0a5#
如果您使用的是旧版本的ES 8+:
字符串