# Delete by query API - data option does not delete documents

**URL:** <https://discuss.elastic.co/t/delete-by-query-api-data-option-does-not-delete-documents/7866>\
**Category:** Elasticsearch\
**Created:** [May 25, 2012, 3:30pm UTC](https://discuss.elastic.co/t/delete-by-query-api-data-option-does-not-delete-documents/7866 "2012-05-25T15:30:14Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Stephan\_Fortelny](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/stephan_fortelny/32/2872_2.png) [@Stephan\_Fortelny](https://discuss.elastic.co/u/Stephan_Fortelny)\
**Post date:** [May 25, 2012, 3:30pm UTC](https://discuss.elastic.co/t/delete-by-query-api-data-option-does-not-delete-documents/7866/1 "2012-05-25T15:30:14Z")

</div>

hi,

I have a problem with the "Delete By Query API", specifically the  
problem is that curl with the data ('-d') option as specified in the  
documentation ([http://www.elasticsearch.org/guide/reference/api/delete-](http://www.elasticsearch.org/guide/reference/api/delete-)  
by-query.html) does not actually delete any documents.

The example from the documentation I refered to, is this one. I didn't  
try them out but I am doing the same, except with different index,  
type and user. However, the first command works for me, the second  
does not.

$ curl -XDELETE '[http://localhost:9200/twitter/tweet/\_query](http://localhost:9200/twitter/tweet/_query)?  
q=user:kimchy'  
$ curl -XDELETE '[http://localhost:9200/twitter/tweet/\_query](http://localhost:9200/twitter/tweet/_query)' -d '{  
"term" : { "user" : "kimchy" }  
}  
'

This gist ([https://gist.github.com/2788743](https://gist.github.com/2788743)) documentates the issue  
more precisely.

Thanks,

Stephan

---

<div class="post-metadata">

**Author:** ![Stephan\_Fortelny](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/stephan_fortelny/32/2872_2.png) [@Stephan\_Fortelny](https://discuss.elastic.co/u/Stephan_Fortelny)\
**Post date:** [May 28, 2012, 1:41pm UTC](https://discuss.elastic.co/t/delete-by-query-api-data-option-does-not-delete-documents/7866/2 "2012-05-28T13:41:18Z")

</div>

I tried the same now the examples given in the documentation (https://  
[default put, get, delete · GitHub](http://gist.github.com/2819256)). For this I am using the same elasticsearch  
installation as well as the same configuration file  
"elasticsearch.yml". Thus, I think that it must having something to do  
with how I index the document in the first place. I index my documents  
using the node.js elasticsearchclient (git://github.com/phillro/node-  
elasticsearch-client.git). The client is basically building up the  
same put request as in the curls.

On May 25, 5:30 pm, Stephan Fortelny [stephanforte...@gmail.com](mailto:stephanforte...@gmail.com)  
wrote:

> hi,
> 
> I have a problem with the "Delete By Query API", specifically the  
> problem is that curl with the data ('-d') option as specified in the  
> documentation ([Elasticsearch Platform — Find real-time answers at scale | Elastic](http://www.elasticsearch.org/guide/reference/api/delete-)  
> by-query.html) does not actually delete any documents.
> 
> The example from the documentation I refered to, is this one. I didn't  
> try them out but I am doing the same, except with different index,  
> type and user. However, the first command works for me, the second  
> does not.
> 
> $ curl -XDELETE '[http://localhost:9200/twitter/tweet/\_query](http://localhost:9200/twitter/tweet/_query)?  
> q=user:kimchy'  
> $ curl -XDELETE '[http://localhost:9200/twitter/tweet/\_query'-d](http://localhost:9200/twitter/tweet/_query'-d) '{  
> "term" : { "user" : "kimchy" }}
> 
> '
> 
> This gist ([elasticsearch - Delete By Query API - data option does not delete data · GitHub](https://gist.github.com/2788743)) documentates the issue  
> more precisely.
> 
> Thanks,
> 
> Stephan

---

<div class="post-metadata">

**Author:** ![Igor\_Motov](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/igor_motov/32/45193_2.png) [@Igor\_Motov](https://discuss.elastic.co/u/Igor_Motov)\
**Post date:** [May 29, 2012, 5:26pm UTC](https://discuss.elastic.co/t/delete-by-query-api-data-option-does-not-delete-documents/7866/3 "2012-05-29T17:26:44Z")

</div>

There is significant difference between term query and text query. The term  
query doesn't analyze the term. So, it's looking for the  
term [stephanfortelny@gmail.com](mailto:stephanfortelny@gmail.com), which doesn't exist in your index (unless  
you are using an old version of elasticsearch). Since the user field is  
analyzed, you index contains two terms "stephanfortelny" and "[gmail.com](http://gmail.com)".  
It happens to works for the term kimchy because it's the same in the  
analyzed and not analyzed forms.

If you want to delete all documents that are returned by your queries, you  
should use the same query in the delete-by-query call:

curl -XDELETE '[http://localhost:9200/contacts/linkedin/\_query](http://localhost:9200/contacts/linkedin/_query)' -d '{  
text: { user: { query: "[stephanfortelny@gmail.com](mailto:stephanfortelny@gmail.com)", operator: "and" } }  
}'

On Monday, May 28, 2012 9:41:18 AM UTC-4, Stephan Fortelny wrote:

> I tried the same now the examples given in the documentation (https://  
> [default put, get, delete · GitHub](http://gist.github.com/2819256)). For this I am using the same elasticsearch  
> installation as well as the same configuration file  
> "elasticsearch.yml". Thus, I think that it must having something to do  
> with how I index the document in the first place. I index my documents  
> using the node.js elasticsearchclient (git://github.com/phillro/node-  
> elasticsearch-client.git[http://github.com/phillro/node-elasticsearch-client.git](http://github.com/phillro/node-elasticsearch-client.git)).  
> The client is basically building up the  
> same put request as in the curls.
> 
> On May 25, 5:30 pm, Stephan Fortelny [stephanforte...@gmail.com](mailto:stephanforte...@gmail.com)  
> wrote:
> 
> > hi,
> > 
> > I have a problem with the "Delete By Query API", specifically the  
> > problem is that curl with the data ('-d') option as specified in the  
> > documentation ([Elasticsearch Platform — Find real-time answers at scale | Elastic](http://www.elasticsearch.org/guide/reference/api/delete-)  
> > by-query.html) does not actually delete any documents.
> > 
> > The example from the documentation I refered to, is this one. I didn't  
> > try them out but I am doing the same, except with different index,  
> > type and user. However, the first command works for me, the second  
> > does not.
> > 
> > $ curl -XDELETE '[http://localhost:9200/twitter/tweet/\_query](http://localhost:9200/twitter/tweet/_query)?  
> > q=user:kimchy'  
> > $ curl -XDELETE '[http://localhost:9200/twitter/tweet/\_query'-d](http://localhost:9200/twitter/tweet/_query'-d) '{  
> > "term" : { "user" : "kimchy" }}
> > 
> > '
> > 
> > This gist ([elasticsearch - Delete By Query API - data option does not delete data · GitHub](https://gist.github.com/2788743)) documentates the issue  
> > more precisely.
> > 
> > Thanks,
> > 
> > Stephan

---

<div class="post-metadata">

**Author:** ![Stephan\_Fortelny](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/stephan_fortelny/32/2872_2.png) [@Stephan\_Fortelny](https://discuss.elastic.co/u/Stephan_Fortelny)\
**Post date:** [May 31, 2012, 8:18pm UTC](https://discuss.elastic.co/t/delete-by-query-api-data-option-does-not-delete-documents/7866/4 "2012-05-31T20:18:50Z")

</div>

yes. that works - for the js api passing the data object as well. thanks a  
lot!

On Tue, May 29, 2012 at 7:26 PM, Igor Motov [imotov@gmail.com](mailto:imotov@gmail.com) wrote:

> There is significant difference between term query and text query. The  
> term query doesn't analyze the term. So, it's looking for the term  
> [stephanfortelny@gmail.com](mailto:stephanfortelny@gmail.com), which doesn't exist in your index (unless you  
> are using an old version of elasticsearch). Since the user field is  
> analyzed, you index contains two terms "stephanfortelny" and "[gmail.com](http://gmail.com)".  
> It happens to works for the term kimchy because it's the same in the  
> analyzed and not analyzed forms.
> 
> If you want to delete all documents that are returned by your queries, you  
> should use the same query in the delete-by-query call:
> 
> curl -XDELETE '[http://localhost:9200/contacts/linkedin/\_query](http://localhost:9200/contacts/linkedin/_query)' -d '{  
> text: { user: { query: "[stephanfortelny@gmail.com](mailto:stephanfortelny@gmail.com)", operator: "and" } }  
> }'
> 
> On Monday, May 28, 2012 9:41:18 AM UTC-4, Stephan Fortelny wrote:
> 
> > I tried the same now the examples given in the documentation (https://  
> > [default put, get, delete · GitHub](http://gist.github.com/2819256)). For this I am using the same elasticsearch  
> > installation as well as the same configuration file  
> > "elasticsearch.yml". Thus, I think that it must having something to do  
> > with how I index the document in the first place. I index my documents  
> > using the node.js elasticsearchclient (git://github.com/phillro/\*\*node-  
> > elasticsearch-client.git[http://github.com/phillro/node-elasticsearch-client.git](http://github.com/phillro/node-elasticsearch-client.git)).  
> > The client is basically building up the  
> > same put request as in the curls.
> > 
> > On May 25, 5:30 pm, Stephan Fortelny [stephanforte...@gmail.com](mailto:stephanforte...@gmail.com)  
> > wrote:
> > 
> > > hi,
> > > 
> > > I have a problem with the "Delete By Query API", specifically the  
> > > problem is that curl with the data ('-d') option as specified in the  
> > > documentation ([http://www.elasticsearch.org/](http://www.elasticsearch.org/)\*\*  
> > > guide/reference/api/delete-[http://www.elasticsearch.org/guide/reference/api/delete-](http://www.elasticsearch.org/guide/reference/api/delete-)  
> > > by-query.html) does not actually delete any documents.
> > > 
> > > The example from the documentation I refered to, is this one. I didn't  
> > > try them out but I am doing the same, except with different index,  
> > > type and user. However, the first command works for me, the second  
> > > does not.
> > > 
> > > $ curl -XDELETE '[http://localhost:9200/\*\*twitter/tweet/\_query](http://localhost:9200/**twitter/tweet/_query)[http://localhost:9200/twitter/tweet/\_query](http://localhost:9200/twitter/tweet/_query)?
> > 
> > > q=user:kimchy'  
> > > $ curl -XDELETE '[http://localhost:9200/\*\*twitter/tweet/\_query'-d\<http://localhost:9200/twitter/tweet/\_query'-d](http://localhost:9200/**twitter/tweet/_query'-d%3Chttp://localhost:9200/twitter/tweet/_query'-d)\>'{  
> > > "term" : { "user" : "kimchy" }}
> > > 
> > > '
> > > 
> > > This gist ([https://gist.github.com/\*\*2788743](https://gist.github.com/**2788743)[https://gist.github.com/2788743](https://gist.github.com/2788743))  
> > > documentates the issue  
> > > more precisely.
> > > 
> > > Thanks,
> > > 
> > > Stephan

---

<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 6, 2017, 3:26am UTC](https://discuss.elastic.co/t/delete-by-query-api-data-option-does-not-delete-documents/7866/5 "2017-07-06T03:26:06Z")

</div>


