# Elasticsearch: Delete by source

**URL:** <https://discuss.elastic.co/t/elasticsearch-delete-by-source/137229>\
**Category:** Elasticsearch\
**Created:** [June 25, 2018, 10:08am UTC](https://discuss.elastic.co/t/elasticsearch-delete-by-source/137229 "2018-06-25T10:08:08Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Uwais\_Ibrahim](https://avatars.discourse-cdn.com/v4/letter/u/b4bc9f/32.png) [@Uwais\_Ibrahim](https://discuss.elastic.co/u/Uwais_Ibrahim)\
**Post date:** [June 25, 2018, 10:08am UTC](https://discuss.elastic.co/t/elasticsearch-delete-by-source/137229/1 "2018-06-25T10:08:09Z")

</div>

Hi,

I need to delete hits from elasticsearch for a specefic source file. I tried below curl commands. Nothing worked instead delete all contents from elastic search. Please help to make it work.

1. curl -XPOST "localhost:9200/filebeat-\*/\_delete\_by\_query?pretty" -H 'Content-Type: application/json' -d' { "query": { "match": { "source": "/path/to/filename.csv" } } }'

2. curl -XPOST "[http://localhost:9200/filebeat-\*/\_delete\_by\_query?\_source='/path/to/filename.csv'](http://localhost:9200/filebeat-*/_delete_by_query?_source='/path/to/filename.csv')" -H 'Content-Type: application/json' -d' { "query": { "match\_all": {} } }'

Thanks,

---

<div class="post-metadata">

**Author:** ![polyfractal](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/polyfractal/32/48162_2.png) [@polyfractal](https://discuss.elastic.co/u/polyfractal)\
**Post date:** [June 26, 2018, 7:00pm UTC](https://discuss.elastic.co/t/elasticsearch-delete-by-source/137229/2 "2018-06-26T19:00:44Z")

</div>

> [@Uwais\_Ibrahim](#):
>
> - curl -XPOST "localhost:9200/filebeat-\*/\_delete\_by\_query?pretty" -H 'Content-Type: application/json' -d' { "query": { "match": { "source": "/path/to/filename.csv" } } }'

How is the `"source"` field mapped? If it's a `text` field, it'll be analyzed and you may be running into issues due to analysis (e.g. `/path/to/filename.csv` could be tokenized into `[path, to, filename, csv]` and matching many documents).

> [@Uwais\_Ibrahim](#):
>
> - curl -XPOST "[http://localhost:9200/filebeat-\*/\_delete\_by\_query?\_source='/path/to/filename.csv'](http://localhost:9200/filebeat-*/_delete_by_query?_source='/path/to/filename.csv')" -H 'Content-Type: application/json' -d' { "query": { "match\_all": {} } }'

This is just incorrect, and will delete all your data. You shouldn't specify the `_source` in the URL.

As a tip, you can run the DBQ query as a regular search first, to make sure it matches the correct documents before deleting.

---

<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:** [July 24, 2018, 7:00pm UTC](https://discuss.elastic.co/t/elasticsearch-delete-by-source/137229/3 "2018-07-24T19:00:44Z")

</div>

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