# Is there a way to delete documents based on \_parent value

**URL:** <https://discuss.elastic.co/t/is-there-a-way-to-delete-documents-based-on-parent-value/110405>\
**Category:** Elasticsearch\
**Created:** [December 5, 2017, 6:14pm UTC](https://discuss.elastic.co/t/is-there-a-way-to-delete-documents-based-on-parent-value/110405 "2017-12-05T18:14:27Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![pamara](https://avatars.discourse-cdn.com/v4/letter/p/958977/32.png) [@pamara](https://discuss.elastic.co/u/pamara)\
**Post date:** [December 5, 2017, 6:14pm UTC](https://discuss.elastic.co/t/is-there-a-way-to-delete-documents-based-on-parent-value/110405/1 "2017-12-05T18:14:28Z")

</div>

Hi All,

I have indexed parent and child documents , child document mapped to parent document based on \_parent value.

How can i delete child documents which all have \_parent value as 'XXX'?

Could you please share the query if any.

Thanks in advance.

---

<div class="post-metadata">

**Author:** ![vivek7mehta](https://avatars.discourse-cdn.com/v4/letter/v/51bf81/32.png) [@vivek7mehta](https://discuss.elastic.co/u/vivek7mehta)\
**Post date:** [December 6, 2017, 7:16am UTC](https://discuss.elastic.co/t/is-there-a-way-to-delete-documents-based-on-parent-value/110405/2 "2017-12-06T07:16:41Z")

</div>

you can use \_delete\_by\_query:  
POST index\_name/child\_type/\_delete\_by\_query  
{  
 "query":  
 {  
  "match":  
  {  
   "\_parent": "XXX"  
  }  
 }  
}

---

<div class="post-metadata">

**Author:** ![pamara](https://avatars.discourse-cdn.com/v4/letter/p/958977/32.png) [@pamara](https://discuss.elastic.co/u/pamara)\
**Post date:** [December 6, 2017, 7:40am UTC](https://discuss.elastic.co/t/is-there-a-way-to-delete-documents-based-on-parent-value/110405/3 "2017-12-06T07:40:36Z")

</div>

Hi Vivek,

This will work fine incase of one child document. Let's say if i want to delete multiple child documents then what should be the query?

Am trying like,  
{  
"query" : {  
"match" : {

```
                "_parent" : [1,2]
            }
        }

```

}

it's giving below error "{"error":{"root\_cause":[{"type":"illegal\_state\_exception","reason":"Can't get text on a START\_ARRAY at 1:30"}],"type":"illegal\_state\_exception","reason":"Can't get text on a START\_ARRAY at 1:30"},"status":500}"

---

<div class="post-metadata">

**Author:** ![vivek7mehta](https://avatars.discourse-cdn.com/v4/letter/v/51bf81/32.png) [@vivek7mehta](https://discuss.elastic.co/u/vivek7mehta)\
**Post date:** [December 6, 2017, 9:47am UTC](https://discuss.elastic.co/t/is-there-a-way-to-delete-documents-based-on-parent-value/110405/4 "2017-12-06T09:47:15Z")

</div>

Just use terms instead of match:

POST index\_name/child\_type/\_delete\_by\_query  
{  
 "query":  
  {  
    "terms": {  
       "\_parent": [1, 2]  
     }  
  }  
}

---

<div class="post-metadata">

**Author:** ![pamara](https://avatars.discourse-cdn.com/v4/letter/p/958977/32.png) [@pamara](https://discuss.elastic.co/u/pamara)\
**Post date:** [December 8, 2017, 1:44pm UTC](https://discuss.elastic.co/t/is-there-a-way-to-delete-documents-based-on-parent-value/110405/5 "2017-12-08T13:44:58Z")

</div>

Hi Vivek,

Above query not worked for me. I haven't get any error but response showing 0 records deleted.

I slightly changed above query(like below) and achieved my goal.

POST index\_name/child\_type/\_delete\_by\_query  
{  
"query":  
{  
"terms": {  
"\_routing": [1, 2]  
}  
}  
}

Thanks & Regards,  
Pradeep Amara.

---

<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:** [January 5, 2018, 1:48pm UTC](https://discuss.elastic.co/t/is-there-a-way-to-delete-documents-based-on-parent-value/110405/6 "2018-01-05T13:48:52Z")

</div>

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