# Filter returns empty on has\_child

**URL:** <https://discuss.elastic.co/t/filter-returns-empty-on-has-child/111631>\
**Category:** Elasticsearch\
**Created:** [December 13, 2017, 7:25pm UTC](https://discuss.elastic.co/t/filter-returns-empty-on-has-child/111631 "2017-12-13T19:25:17Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![ryanmcclure4](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/ryanmcclure4/32/23712_2.png) [@ryanmcclure4](https://discuss.elastic.co/u/ryanmcclure4)\
**Post date:** [December 13, 2017, 7:25pm UTC](https://discuss.elastic.co/t/filter-returns-empty-on-has-child/111631/1 "2017-12-13T19:25:17Z")

</div>

I have an index that can either be a _thread_ or a _thread\_item_, where a _thread_ is the parent of one or more _thread\_item_. In the template, I have the following defined in my template for a field called _messages_:

```
...
    "message" : {
      "properties" : {
        "mentions" : {
          "type" : "nested",
          "properties" : {
            "contact" : {
              "type" : "nested",
              "properties" : {
                "first_name" : {
                  "type" : "text",
                  "fields" : {
                    "keyword" : {
                      "type" : "keyword",
                      "ignore_above" : 256
                    }
                  }
                },
                "id" : {
                  "type" : "long"
                },
                "last_name" : {
                  "type" : "text",
                  "fields" : {
                    "keyword" : {
                      "type" : "keyword",
                      "ignore_above" : 256
                    }
                  }
                }
              }
            }
          }
        }
    }
}
...

```

I would like to use a nested filter to find a _thread_ which has a child _thread\_item_ that has a matching mention.contact.first\_name value:

```
{  
   "query":{  
      "bool":{  
         "filter":{  
            "has_child":{  
               "type":"thread_item",
               "query":{  
                  "nested":{  
                     "path":"message.mentions",
                     "query":{  
                        "nested":{  
                           "path":"message.mentions.contact",
                           "query":{  
                              "term":{  
                                 "message.mentions.contact.first_name":"aaron"
                              }
                           }
                        }
                     }
                  }
               }
            }
         }
      }
   }
}

```

The above does not work even when there is an existing matching record. If i remove the has\_child portion of the query, it does work and returns the correct record:

```
{  
   "query":{  
      "bool":{  
         "filter":{  
            "nested":{  
               "path":"message.mentions",
               "query":{  
                  "nested":{  
                     "path":"message.mentions.contact",
                     "query":{  
                        "match":{  
                           "message.mentions.contact.first_name":"aaron"
                        }
                     }
                  }
               }
            }
         }
      }
   }
}

```

Is there something wrong with the way I'm writing the has\_child query? I've written many other queries using this relationship which all work fine, so I'm pretty sure it's not a type issue.

---

<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 10, 2018, 7:25pm UTC](https://discuss.elastic.co/t/filter-returns-empty-on-has-child/111631/2 "2018-01-10T19:25:47Z")

</div>

Closed on January 10, 2018, 7:25pm UTC

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