# How to delete particular document from multiple indices in elasticsearch using python?

**URL:** https://discuss.elastic.co/t/how-to-delete-particular-document-from-multiple-indices-in-elasticsearch-using-python/116584
**Category:** Elasticsearch
**Created:** [January 23, 2018, 4:21am UTC](https://discuss.elastic.co/t/how-to-delete-particular-document-from-multiple-indices-in-elasticsearch-using-python/116584 "2018-01-23T04:21:16Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![akashtalole](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/akashtalole/32/26821_2.png) [@akashtalole](https://discuss.elastic.co/u/akashtalole)
#### Post date: [January 23, 2018, 4:21am UTC](https://discuss.elastic.co/t/how-to-delete-particular-document-from-multiple-indices-in-elasticsearch-using-python/116584/1 "2018-01-23T04:21:16Z")

</div>

Here is sample document.

```
{
"_index": "mqtt-index-2018.01.22",
"_type": "iot_data",
"_id": "AHWewerdfdfdfdfRTRRfdfgf",
"_score": 1,
"_source": {
"message": "{\"datastream_name\": \"teststream1\", \"value\": 2, \"context\": {\"latitude\": 0, 
\"elevation\": 0, \"longitude\": 0}, \"device_id\": 15}",
"@version": "1",
"@timestamp": "2018-01-22T11:47:52.175Z",
"host": "iot-elk",
"topic": "telemetry/df42e78206d946a3a2863d167af9063b/teststream1",
"parsedMessage": {
"datastream_name": "teststream1",
  "value": 2,
  "context": {
    "latitude": 0,
    "elevation": 0,
    "longitude": 0
  },
  "device_id": 15,
  "tstamp": "2018-01-22T11:47:52.175Z"
}
},
"fields": {
"parsedMessage.tstamp": [
  1516621672175
],
"@timestamp": [
  1516621672175
]
}
}

```

I want to delete document using parsedMessage.device\_id. how to delete it using python client?

---

<div class="post-metadata">

### Author: ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)
#### Post date: [January 23, 2018, 7:24am UTC](https://discuss.elastic.co/t/how-to-delete-particular-document-from-multiple-indices-in-elasticsearch-using-python/116584/2 "2018-01-23T07:24:39Z")

</div>

Please format your code using `</>` icon as explained in [this guide](https://discuss.elastic.co/t/about-the-elasticsearch-category/21) and not the citation button. It will make your post more readable.

Or use markdown style like:

````
```
CODE
```

````

Please edit your post.

You can use delete by query feature but I don't know how you call it from python.  
Easier may be to do that in Kibana Dev Console.

---

<div class="post-metadata">

### Author: ![akashtalole](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/akashtalole/32/26821_2.png) [@akashtalole](https://discuss.elastic.co/u/akashtalole)
#### Post date: [January 24, 2018, 10:04am UTC](https://discuss.elastic.co/t/how-to-delete-particular-document-from-multiple-indices-in-elasticsearch-using-python/116584/3 "2018-01-24T10:04:33Z")

</div>

It works. 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
```

---

<div class="post-metadata">

### Author: ![akashtalole](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/akashtalole/32/26821_2.png) [@akashtalole](https://discuss.elastic.co/u/akashtalole)
#### Post date: [January 24, 2018, 10:05am UTC](https://discuss.elastic.co/t/how-to-delete-particular-document-from-multiple-indices-in-elasticsearch-using-python/116584/4 "2018-01-24T10:05:22Z")

</div>

You can also delete documents with matching multiple fields.

```
curl -XDELETE 'http://localhost:9200/mqtt-index-*/logs/_query' -d '{
"query" : {
    "bool": {
        "must":[
    {"match" : {"device_id":31}}, 
    {"match": {"datastream_name": "test"}}
    ]
}
}' -i
```

---

<div class="post-metadata">

### Author: ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)
#### Post date: [February 21, 2018, 10:05am UTC](https://discuss.elastic.co/t/how-to-delete-particular-document-from-multiple-indices-in-elasticsearch-using-python/116584/5 "2018-02-21T10:05:36Z")

</div>

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.
