# Can't delete data with python script

**URL:** <https://discuss.elastic.co/t/cant-delete-data-with-python-script/209963>\
**Category:** Elasticsearch\
**Created:** [November 29, 2019, 11:29am UTC](https://discuss.elastic.co/t/cant-delete-data-with-python-script/209963 "2019-11-29T11:29:39Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Ramon\_Mateo](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/ramon_mateo/32/46306_2.png) [@Ramon\_Mateo](https://discuss.elastic.co/u/Ramon_Mateo)\
**Post date:** [November 29, 2019, 11:29am UTC](https://discuss.elastic.co/t/cant-delete-data-with-python-script/209963/1 "2019-11-29T11:29:39Z")

</div>

Hi

I am trying to make a script that deletes the old elasticsearch data. My problem is that in the read\_only\_allow\_delete

In the code attached I try to put a put but it returns error 406.

Any ideas or solutions?

Thank you very much

```
if __name__ == ' __main__':

es = Elasticsearch("http://.../")
res = requests.put(url= "... :9200/_settings" ,data= {"index": {"blocks": {"read_only_allow_delete": "false"}}})
#res = es.search(index = "lab" , body= {"query": {"range": {"@timestamp": {"gte": "now-7d/d","lte": "now-7d/d"}}}})
res = es.delete_by_query(index = 'lab-benchmarking-csv' , body={"query": {"range": {"@timestamp": {"gte": "now-7d/d","lte": "now/d"}}}} , request_timeout=30)
```

---

<div class="post-metadata">

**Author:** ![Christian\_Dahlqvist](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/christian_dahlqvist/32/4617_2.png) [@Christian\_Dahlqvist](https://discuss.elastic.co/u/Christian_Dahlqvist)\
**Post date:** [November 29, 2019, 12:11pm UTC](https://discuss.elastic.co/t/cant-delete-data-with-python-script/209963/2 "2019-11-29T12:11:48Z")

</div>

Delete by query will do an update behind the scenes an at least temporarily increase disk usage. If you are suffering from high disk usage this way of removing data will not work.

---

<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:** [December 27, 2019, 12:11pm UTC](https://discuss.elastic.co/t/cant-delete-data-with-python-script/209963/3 "2019-12-27T12:11:56Z")

</div>

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