How To Execute This Curl In Python 2.7 To Delete Documents From Elasticsearch?
Hello I am new to python and elasticsearch. On my local I have setup Elasticsearch and have added data to it. http://127.0.0.1:9200/index_data/type_data. I want to delete some _ids
Solution 1:
If there are a lot of ids, try parallel_bulk deletion in python: documentaion here: http://elasticsearch-py.readthedocs.io/en/master/helpers.html#elasticsearch.helpers.parallel_bulk
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)
Post a Comment for "How To Execute This Curl In Python 2.7 To Delete Documents From Elasticsearch?"