如何在python 2.7中执行此CURL以从Elasticsearch中删除文档?
您好,我是python和elasticsearch的新手。在我的本地计算机上,我已设置Elasticsearch并已向其添加数据 我想从type_数据中删除一些_id。 假设要删除的_id列表是x=['a','b','c'.'d'] curl-xdelite'localhost:9200/index\u data/type\u data/a?pretty' 使用这个命令,我可以从elasticsearch中删除一个特定的_id,但是如何使用python执行这个curl请求呢 是否可以使用python删除整个type_数据 为什么这个代码不起作用 我正在使用 Elasticsearch版本6.1.0。 elasticsearch py版本5.4.0如何在python 2.7中执行此CURL以从Elasticsearch中删除文档?,python,python-2.7,curl,
elasticsearch,Python,Python 2.7,Curl,
elasticsearch,您好,我是python和elasticsearch的新手。在我的本地计算机上,我已设置Elasticsearch并已向其添加数据 我想从type_数据中删除一些_id。 假设要删除的_id列表是x=['a','b','c'.'d'] curl-xdelite'localhost:9200/index\u data/type\u data/a?pretty' 使用这个命令,我可以从elasticsearch中删除一个特定的_id,但是如何使用python执行这个curl请求呢 是否可以使用pyth
请帮帮我 如果有很多ID,请尝试在python中并行批量删除: 文件在此:
但是,对于检索具有特定数据类型的所有文档,最佳做法是使用扫描查询-滚动api。在Python中:helpers.scan(es,query={“query”:{“query”:{“match_all”:{}}},index=“es_index”,doc_type=“your_data_type”)
from elasticsearch import Elasticsearch
es = Elasticsearch()
request_body = {
"query": {
"ids": {
"values": ['a','b','c','d','e','f']
}
}
}
es.delete_by_query(index=es_index, body=request_body)
from elasticsearch import Elasticsearch
from elasticsearch import helpers
es = Elasticsearch()
index_name = es_index
doc_type = your_doc_type
ids = ['a','b','c','d','e','f']
def generate_actions(ids):
for i in ids:
yield {
'_op_type': 'delete',
'_index': index_name,
'_type': doc_type,
'_id': i
}
for success, info in helpers.parallel_bulk(client=es, actions=generate_actions(ids), thread_count=4):
if not success:
print('Doc failed', info)