How to delete documents from multiple indices using particular field name in elasticsearch python?
Deleting document from multiple indices in elasticsearch using following DELETE API call.
curl -XDELETE 'http://localhost:9200/mqtt-index-*/logs/_query' -d '{"query" : { "match" : {"device_id": 31}}}' -i
Short answer without sample code:
- convert the json to a dict (see Converting JSON String to Dictionary Not List)
- if you have many of those data structures, build a list of them if they match your search criteria (e.g.
if data["parsed_message"]["device_id"] not in list_of_forbidden_ids):
)
In terms of using the raw API, I believe this is what you are looking for.
Depending on which python library you are using, it is actually easier in python. I use elasticesearch-dsl-py
, where you build up query objects. You can call delete on these query objects.
In regards to spanning multiple indexes, ElasticSearch does support this, either using a wildcard *
, or separating the indexes with commas.