# Delete By Query

**URL:** <https://discuss.elastic.co/t/delete-by-query/8188>\
**Category:** Elasticsearch\
**Created:** [June 22, 2012, 6:43am UTC](https://discuss.elastic.co/t/delete-by-query/8188 "2012-06-22T06:43:15Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![ppcharli](https://avatars.discourse-cdn.com/v4/letter/p/53a042/32.png) [@ppcharli](https://discuss.elastic.co/u/ppcharli)\
**Post date:** [June 22, 2012, 6:43am UTC](https://discuss.elastic.co/t/delete-by-query/8188/1 "2012-06-22T06:43:15Z")

</div>

Hi,

If I run a query I get results but if I run the same query to delete does  
not work.

curl -XGET '[http://localhost:9200/alias1/facturas/\_search?pretty](http://localhost:9200/alias1/facturas/_search?pretty)' -d  
'{"query":{"query\_string":{"query":"cliente:(cliente\*)"}}}'  
{  
"took" : 3,  
"timed\_out" : false,  
"\_shards" : {  
"total" : 4,  
"successful" : 4,  
"failed" : 0  
},  
"hits" : {  
"total" : 3,  
"max\_score" : 1.0,  
"hits" : [ {  
"\_index" : "indice1",  
"\_type" : "facturas",  
"\_id" : "1-1",  
"\_score" : 1.0, "\_source" :  
{"id":"1","cliente":"cliente1","org":"1","total":"1001"}  
}, {  
"\_index" : "indice1",  
"\_type" : "facturas",  
"\_id" : "1-1",  
"\_score" : 1.0, "\_source" :  
{"id":"1","cliente":"cliente1","org":"1","total":"1005"}  
}, {  
"\_index" : "indice1",  
"\_type" : "facturas",  
"\_id" : "1-1",  
"\_score" : 1.0, "\_source" :  
{"id":"1","cliente":"cliente1","org":"1","total":"1006"}  
} ]  
}  
}

curl -XDELETE '[http://localhost:9200/alias1/facturas/\_query](http://localhost:9200/alias1/facturas/_query)' -d  
'{"query":{"query\_string":{"query":"cliente:(cliente\*)"}}}'

{"ok":true,"\_indices":{"indice1":{"\_shards":{"total":4,"successful":0,"failed":4}}}}

Thanks,

---

<div class="post-metadata">

**Author:** ![dkoum](https://avatars.discourse-cdn.com/v4/letter/d/9dc877/32.png) [@dkoum](https://discuss.elastic.co/u/dkoum)\
**Post date:** [June 22, 2012, 6:53am UTC](https://discuss.elastic.co/t/delete-by-query/8188/2 "2012-06-22T06:53:31Z")

</div>

I asked the same question a while ago, response was to drop first the  
"query" and use a "query\_string" directly like this: -d  
'{"query\_string":{"query":"cliente: .....

On Fri, Jun 22, 2012 at 9:43 AM, ppcharli [ppcharli@gmail.com](mailto:ppcharli@gmail.com) wrote:

> Hi,
> 
> If I run a query I get results but if I run the same query to delete does  
> not work.
> 
> curl -XGET '[http://localhost:9200/alias1/facturas/\_search?pretty](http://localhost:9200/alias1/facturas/_search?pretty)' -d  
> '{"query":{"query\_string":{"query":"cliente:(cliente\*)"}}}'  
> {  
> "took" : 3,  
> "timed\_out" : false,  
> "\_shards" : {  
> "total" : 4,  
> "successful" : 4,  
> "failed" : 0  
> },  
> "hits" : {  
> "total" : 3,  
> "max\_score" : 1.0,  
> "hits" : [ {  
> "\_index" : "indice1",  
> "\_type" : "facturas",  
> "\_id" : "1-1",  
> "\_score" : 1.0, "\_source" :  
> {"id":"1","cliente":"cliente1","org":"1","total":"1001"}  
> }, {  
> "\_index" : "indice1",  
> "\_type" : "facturas",  
> "\_id" : "1-1",  
> "\_score" : 1.0, "\_source" :  
> {"id":"1","cliente":"cliente1","org":"1","total":"1005"}  
> }, {  
> "\_index" : "indice1",  
> "\_type" : "facturas",  
> "\_id" : "1-1",  
> "\_score" : 1.0, "\_source" :  
> {"id":"1","cliente":"cliente1","org":"1","total":"1006"}  
> } ]  
> }  
> }
> 
> curl -XDELETE '[http://localhost:9200/alias1/facturas/\_query](http://localhost:9200/alias1/facturas/_query)' -d  
> '{"query":{"query\_string":{"query":"cliente:(cliente\*)"}}}'
> 
> {"ok":true,"\_indices":{"indice1":{"\_shards":{"total":4,"successful":0,"failed":4}}}}
> 
> Thanks,

---

<div class="post-metadata">

**Author:** ![ppcharli](https://avatars.discourse-cdn.com/v4/letter/p/53a042/32.png) [@ppcharli](https://discuss.elastic.co/u/ppcharli)\
**Post date:** [June 22, 2012, 7:17am UTC](https://discuss.elastic.co/t/delete-by-query/8188/3 "2012-06-22T07:17:26Z")

</div>

Thanks Dionisis ,

On Friday, June 22, 2012 8:53:31 AM UTC+2, dkoum wrote:

> I asked the same question a while ago, response was to drop first the  
> "query" and use a "query\_string" directly like this: -d  
> '{"query\_string":{"query":"cliente: .....
> 
> On Fri, Jun 22, 2012 at 9:43 AM, ppcharli [ppcharli@gmail.com](mailto:ppcharli@gmail.com) wrote:
> 
> > Hi,
> > 
> > If I run a query I get results but if I run the same query to delete does  
> > not work.
> > 
> > curl -XGET '[http://localhost:9200/alias1/facturas/\_search?pretty](http://localhost:9200/alias1/facturas/_search?pretty)' -d  
> > '{"query":{"query\_string":{"query":"cliente:(cliente\*)"}}}'  
> > {  
> > "took" : 3,  
> > "timed\_out" : false,  
> > "\_shards" : {  
> > "total" : 4,  
> > "successful" : 4,  
> > "failed" : 0  
> > },  
> > "hits" : {  
> > "total" : 3,  
> > "max\_score" : 1.0,  
> > "hits" : [ {  
> > "\_index" : "indice1",  
> > "\_type" : "facturas",  
> > "\_id" : "1-1",  
> > "\_score" : 1.0, "\_source" :  
> > {"id":"1","cliente":"cliente1","org":"1","total":"1001"}  
> > }, {  
> > "\_index" : "indice1",  
> > "\_type" : "facturas",  
> > "\_id" : "1-1",  
> > "\_score" : 1.0, "\_source" :  
> > {"id":"1","cliente":"cliente1","org":"1","total":"1005"}  
> > }, {  
> > "\_index" : "indice1",  
> > "\_type" : "facturas",  
> > "\_id" : "1-1",  
> > "\_score" : 1.0, "\_source" :  
> > {"id":"1","cliente":"cliente1","org":"1","total":"1006"}  
> > } ]  
> > }  
> > }
> > 
> > curl -XDELETE '[http://localhost:9200/alias1/facturas/\_query](http://localhost:9200/alias1/facturas/_query)' -d  
> > '{"query":{"query\_string":{"query":"cliente:(cliente\*)"}}}'
> > 
> > {"ok":true,"\_indices":{"indice1":{"\_shards":{"total":4,"successful":0,"failed":4}}}}
> > 
> > Thanks,

---

<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:22am UTC](https://discuss.elastic.co/t/delete-by-query/8188/4 "2017-07-06T03:22:58Z")

</div>


