# Delete by Query: transaction like?

**URL:** <https://discuss.elastic.co/t/delete-by-query-transaction-like/10257>\
**Category:** Elasticsearch\
**Created:** [January 8, 2013, 12:16am UTC](https://discuss.elastic.co/t/delete-by-query-transaction-like/10257 "2013-01-08T00:16:15Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![phill](https://avatars.discourse-cdn.com/v4/letter/p/779978/32.png) [@phill](https://discuss.elastic.co/u/phill)\
**Post date:** [January 8, 2013, 12:16am UTC](https://discuss.elastic.co/t/delete-by-query-transaction-like/10257/1 "2013-01-08T00:16:15Z")

</div>

I have a three-level parent child: MyGrandParentType, MyParentType,  
MyChildType  
Is a good way to use delete-by-query to build \*one \*big query that  
deletes a grandparent, a parent and all children all at the same time?  
I'm guessing this would be a "bool" Query with 3 parts: find the right  
grandparent, the right parent, and the right children.

In the example below, the assumption is I have the grandparent ID  
"myGrandID" and parent ID "myParentID" and that grandparent to parent is  
1:1.

"query": {  
"bool": {  
"should": [  
"bool": {  
"must": [  
"term": { "\_type":"MyGrandParentType" },  
"term": { "\_id": "myGrandID" }  
]  
},  
"bool": {  
"must": [  
"term": { "\_type":"MyParentType" },  
"term": { "\_id": "myParentID" }  
]  
},  
"bool": {  
"must": [  
"term": { "\_type":"MyChildType" },  
"term": { "\_parent": "myParentId" }  
]  
}  
],  
"|minimum\_number\_should\_match": 3|  
}  
}

I would also specify routing by myGrandID and explicitly list the three  
types in the request. I am also expecting this only be a request to one  
index.

Does this one-big-query approach have any advantages or disadvantages  
over 3 separate delete by query requests one delete quest for each type  
(other than 1 instead of 3 requests) ?  
Does this one big delete-by-query actually do it as a "transaction"?  
By "transaction", I'm wondering if the entire thing will fail or succeed  
as one, because I'm using routing, so it is really going to succeed or  
fail on one shard and either it finds them all and deletes them all or  
it doesn't.

I could query before I delete, so I could make the  
"|minimum\_number\_should\_match" exact ( 1 grand + 1 parent + n  
children).||Would that have any advantage to making it more  
transaction-like?|

-Paul

--

---

<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, 2:57am UTC](https://discuss.elastic.co/t/delete-by-query-transaction-like/10257/2 "2017-07-06T02:57:30Z")

</div>

Closed on July 6, 2017, 2:57am UTC


