# Elastic search: Nested query with and condition on parent and child

**URL:** <https://discuss.elastic.co/t/elastic-search-nested-query-with-and-condition-on-parent-and-child/70637>\
**Category:** Elasticsearch\
**Created:** [January 5, 2017, 5:55am UTC](https://discuss.elastic.co/t/elastic-search-nested-query-with-and-condition-on-parent-and-child/70637 "2017-01-05T05:55:01Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![nishant35](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/nishant35/32/14244_2.png) [@nishant35](https://discuss.elastic.co/u/nishant35)\
**Post date:** [January 5, 2017, 5:55am UTC](https://discuss.elastic.co/t/elastic-search-nested-query-with-and-condition-on-parent-and-child/70637/1 "2017-01-05T05:55:01Z")

</div>

I have 2 sample record like below:

```
{
    "parents": [
      {
        "child": [
          {
            "is_deleted": false,
            "child_id": -1,
            "timestamp": 1483536052232
          }
        ],
        "parent_id": 810
      },
      {
        "child": [
          {
            "is_deleted": true,
            "child_id": 105,
            "timestamp": 1483537567000
          }
        ],
        "parent_id": 42
      }
    ]
},
{
  "parents": [
      {
        "child": [
          {
            "is_deleted": false,
            "child_id": 105,
            "timestamp": 1483537567000
          }
        ],
        "parent_id": 42
      }
    ]
}

```

and my mapping:

```
"properties": {
  "parents": {
    "type": "nested",
    "properties": {
      "parent_id": {
        "type": "integer",
        "doc_values": false
      },
      "child": {
        "type": "nested",
        "properties": {
          "is_deleted": {
            "type": "boolean",
            "doc_values": false
          },
          "child_id": {
            "type": "integer",
            "doc_values": false
          },
          "timestamp": {
            "type": "long",
            "doc_values": false
          }
        }
      }
    }
  }

```

I want to search by parent ID which has at least one child with `is_deleted` as false. For example if i will query with parent ID 42, i should get only 2nd document not first.

---

<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:** [February 2, 2017, 5:55am UTC](https://discuss.elastic.co/t/elastic-search-nested-query-with-and-condition-on-parent-and-child/70637/2 "2017-02-02T05:55:15Z")

</div>

Closed on February 2, 2017, 5:55am UTC

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