# How to Filter Parent based on Children terms

**URL:** <https://discuss.elastic.co/t/how-to-filter-parent-based-on-children-terms/128978>\
**Category:** Elasticsearch\
**Created:** [April 21, 2018, 8:01pm UTC](https://discuss.elastic.co/t/how-to-filter-parent-based-on-children-terms/128978 "2018-04-21T20:01:12Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Syed\_ali\_abbas\_shah](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/syed_ali_abbas_shah/32/30053_2.png) [@Syed\_ali\_abbas\_shah](https://discuss.elastic.co/u/Syed_ali_abbas_shah)\
**Post date:** [April 21, 2018, 8:01pm UTC](https://discuss.elastic.co/t/how-to-filter-parent-based-on-children-terms/128978/1 "2018-04-21T20:01:12Z")

</div>

I want to get those parent users where users not blocked particular user  
Here is my mapping

```auto
{
	"properties": {
		"id": {
			"type": "keyword"
		},
	
		"username": {
			"type": "text",
			"fields": {
				"raw": {
					"type": "keyword",
					"index": false
				}
			}
		},
		"created_at": {
			"type": "date"
		},
		"updated_at": {
			"type": "date"
		},
		"type": {
			"type": "join",
			"relations": {
				"user": [
					"block"
				]
			}
		}
	}
}

```

My Query is

```auto
GET /trendings/movie/_search
{

  "size":2000,
  "query": {
    "bool": {
      "must": [
        {
          "term":{
            "type":"user"
          }
        },
        {
          "has_child": {
         
            "type": "block",
             "query":{
               "bool":{
                 "must_not": [
                   {
                     "terms":{
                       "id":["260"]
                     }
                   }
                 ]
               }
             }
          }
        }
      ]
    }
  }
}

```

but a parent that contains block user 260 is coming in result, is there any way to filter parent based on children must\_not

---

<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:** [May 19, 2018, 8:01pm UTC](https://discuss.elastic.co/t/how-to-filter-parent-based-on-children-terms/128978/2 "2018-05-19T20:01:12Z")

</div>

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