Delete child document without parent

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

Here is an example.

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

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

Then you can use has_parent query with ids query.

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

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

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