# Delete file from index with \_delete\_by\_query empties the index

**URL:** <https://discuss.elastic.co/t/delete-file-from-index-with-delete-by-query-empties-the-index/217382>\
**Category:** Elasticsearch\
**Created:** [January 31, 2020, 1:39pm UTC](https://discuss.elastic.co/t/delete-file-from-index-with-delete-by-query-empties-the-index/217382 "2020-01-31T13:39:50Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![Tommie](https://avatars.discourse-cdn.com/v4/letter/t/f0a364/32.png) [@Tommie](https://discuss.elastic.co/u/Tommie)\
**Post date:** [January 31, 2020, 1:39pm UTC](https://discuss.elastic.co/t/delete-file-from-index-with-delete-by-query-empties-the-index/217382/1 "2020-01-31T13:39:50Z")

</div>

I've tried to delete one of the imported files (csv logstash import) from my index by using:

POST /myindex/\_delete\_by\_query  
{  
"query": {  
"match": {  
"path": "filename.ext"  
}  
}  
}

My intention was to delete only the documents related to the filename.ext import from myindex.

The action caused the complete index to be empty. Am I misinterpreting this statement?

---

<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 31, 2020, 1:56pm UTC](https://discuss.elastic.co/t/delete-file-from-index-with-delete-by-query-empties-the-index/217382/2 "2020-01-31T13:56:32Z")

</div>

It depends on the analyzer, mapping how you exactly run it, if by mistake you put a blank line between the POST line and the json body.

Could you provide a full recreation script as described in [About the Elasticsearch category](https://discuss.elastic.co/t/about-the-elasticsearch-category/21). It will help to better understand what you are doing. Please, try to keep the example as simple as possible.

A full reproduction script will help readers to understand, reproduce and if needed fix your problem. It will also most likely help to get a faster answer.

---

<div class="post-metadata">

**Author:** ![Tommie](https://avatars.discourse-cdn.com/v4/letter/t/f0a364/32.png) [@Tommie](https://discuss.elastic.co/u/Tommie)\
**Post date:** [February 3, 2020, 1:12pm UTC](https://discuss.elastic.co/t/delete-file-from-index-with-delete-by-query-empties-the-index/217382/3 "2020-02-03T13:12:08Z")

</div>

Sorry for not formatting my code correctly.

```
POST /myindexname/_delete_by_query 
{
"query": {
"match": {
"path": "c:/myinputpath/MyCSVFile20200125.log"
}
}
}
```

---

<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:** [February 3, 2020, 2:06pm UTC](https://discuss.elastic.co/t/delete-file-from-index-with-delete-by-query-empties-the-index/217382/4 "2020-02-03T14:06:50Z")

</div>

I'd I try to execute your code, it will tell me that the index does not exist.  
It's not a full reproduction script.

---

<div class="post-metadata">

**Author:** ![Tommie](https://avatars.discourse-cdn.com/v4/letter/t/f0a364/32.png) [@Tommie](https://discuss.elastic.co/u/Tommie)\
**Post date:** [February 3, 2020, 2:25pm UTC](https://discuss.elastic.co/t/delete-file-from-index-with-delete-by-query-empties-the-index/217382/5 "2020-02-03T14:25:00Z")

</div>

Thanks for your reaction. Sorry, I don't understand what you mean.  
This is an index on my system, so why do you expect the index to exist?

I've just retried to delete the document of only one imported file. Tried without the directory but only with the filename, but again I ended up with a complete empty index.

---

<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:** [February 3, 2020, 2:42pm UTC](https://discuss.elastic.co/t/delete-file-from-index-with-delete-by-query-empties-the-index/217382/6 "2020-02-03T14:42:46Z")

</div>

> [@Tommie](#):
>
> This is an index on my system, so why do you expect the index to exist?

Because I asked for this:

> [@dadoonet](#):
>
> Could you provide a full recreation script as described in [About the Elasticsearch category](https://discuss.elastic.co/t/about-the-elasticsearch-category/21). It will help to better understand what you are doing. Please, try to keep the example as simple as possible.
> 
> A full reproduction script will help readers to understand, reproduce and if needed fix your problem. It will also most likely help to get a faster answer.

---

<div class="post-metadata">

**Author:** ![Tommie](https://avatars.discourse-cdn.com/v4/letter/t/f0a364/32.png) [@Tommie](https://discuss.elastic.co/u/Tommie)\
**Post date:** [February 4, 2020, 8:06am UTC](https://discuss.elastic.co/t/delete-file-from-index-with-delete-by-query-empties-the-index/217382/7 "2020-02-04T08:06:23Z")

</div>

I've found another way to do it:

```
POST /myindexname/_delete_by_query?q=path:"MyCSVFile20200125.log"

```

works perfect!

---

<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:** [March 3, 2020, 8:06am UTC](https://discuss.elastic.co/t/delete-file-from-index-with-delete-by-query-empties-the-index/217382/8 "2020-03-03T08:06:30Z")

</div>

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