# Delete child document without parent

**URL:** <https://discuss.elastic.co/t/delete-child-document-without-parent/305745>\
**Category:** Elasticsearch\
**Created:** [May 26, 2022, 6:50pm UTC](https://discuss.elastic.co/t/delete-child-document-without-parent/305745 "2022-05-26T18:50:25Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![Udayaprakash\_S\_10d](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/udayaprakash_s_10d/32/105116_2.png) [@Udayaprakash\_S\_10d](https://discuss.elastic.co/u/Udayaprakash_S_10d)\
**Post date:** [May 26, 2022, 6:50pm UTC](https://discuss.elastic.co/t/delete-child-document-without-parent/305745/1 "2022-05-26T18:50:26Z")

</div>

i want to delete the child document in the index with out parent .i want delete query for this

---

<div class="post-metadata">

**Author:** ![Tomo\_M](https://avatars.discourse-cdn.com/v4/letter/t/848f3c/32.png) [@Tomo\_M](https://discuss.elastic.co/u/Tomo_M)\
**Post date:** [May 27, 2022, 3:30am UTC](https://discuss.elastic.co/t/delete-child-document-without-parent/305745/2 "2022-05-27T03:30:13Z")

</div>

Here is an example.

```auto
PUT test_parent
{
  "mappings": {
    "properties": {
      "my-join-field": {
        "type": "join",
        "relations": {
          "_parent": "_child"
        }
      },
      "tag": {
        "type": "keyword"
      }
    }
  }
}

POST test_parent/_doc/1
{
  "my-join-field": {
    "name": "_parent"
  },
  "tag": "parent_A"
}

POST test_parent/_doc/2?routing=1
{
  "my-join-field": {
    "name": "_child",
    "parent": "does not exist"
  },
  "tag": "child_A"
}

POST test_parent/_doc/3?routing=1
{
  "my-join-field": {
    "name": "_child",
    "parent": "1"
  },
  "tag": "child_B"
}

GET test_parent/_search

POST test_parent/_delete_by_query
{
  "query":{
    "bool": {
      "filter": [
        {"term": {
          "my-join-field": "_child"
        }}
      ], 
      "must_not": [
        {
          "has_parent": {
            "parent_type": "_parent",
            "query": {"match_all":{}}
          }
        }
      ]
    }
  }
}

GET test_parent/_search

```

---

<div class="post-metadata">

**Author:** ![Udayaprakash\_S\_10d](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/udayaprakash_s_10d/32/105116_2.png) [@Udayaprakash\_S\_10d](https://discuss.elastic.co/u/Udayaprakash_S_10d)\
**Post date:** [May 27, 2022, 8:55am UTC](https://discuss.elastic.co/t/delete-child-document-without-parent/305745/3 "2022-05-27T08:55:28Z")

</div>

thanks for ur reply,i want to delete the child document with respect to id for particular parent

---

<div class="post-metadata">

**Author:** ![Tomo\_M](https://avatars.discourse-cdn.com/v4/letter/t/848f3c/32.png) [@Tomo\_M](https://discuss.elastic.co/u/Tomo_M)\
**Post date:** [May 27, 2022, 2:50pm UTC](https://discuss.elastic.co/t/delete-child-document-without-parent/305745/4 "2022-05-27T14:50:51Z")

</div>

Then you can use[has\_paren](https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-has-parent-query.html)t query with [ids](https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-ids-query.html) query.

---

<div class="post-metadata">

**Author:** ![Udayaprakash\_S\_10d](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/udayaprakash_s_10d/32/105116_2.png) [@Udayaprakash\_S\_10d](https://discuss.elastic.co/u/Udayaprakash_S_10d)\
**Post date:** [May 30, 2022, 9:36am UTC](https://discuss.elastic.co/t/delete-child-document-without-parent/305745/5 "2022-05-30T09:36:50Z")

</div>

Thanks ,i deleted the child document ,need one more help that is,parent document have multiple child document ,need to fetch one child doc with respect to id from particular parent

need query for above scenario

---

<div class="post-metadata">

**Author:** ![Udayaprakash\_S\_10d](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/udayaprakash_s_10d/32/105116_2.png) [@Udayaprakash\_S\_10d](https://discuss.elastic.co/u/Udayaprakash_S_10d)\
**Post date:** [May 30, 2022, 10:05am UTC](https://discuss.elastic.co/t/delete-child-document-without-parent/305745/6 "2022-05-30T10:05:08Z")

</div>

```auto
GET /my-index-000001/_search
{
  "query": {
      "parent_id": {
          "type": "my-child",
          "id": "1"
      }
  }
}

```

this will return list of child documents.but i need one child with respect to id

---

<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:** [June 27, 2022, 10:06am UTC](https://discuss.elastic.co/t/delete-child-document-without-parent/305745/7 "2022-06-27T10:06:05Z")

</div>

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