# IS there a way to search on parent fields from a nested query?

**URL:** https://discuss.elastic.co/t/is-there-a-way-to-search-on-parent-fields-from-a-nested-query/198385
**Category:** Elasticsearch
**Created:** [September 6, 2019, 9:26am UTC](https://discuss.elastic.co/t/is-there-a-way-to-search-on-parent-fields-from-a-nested-query/198385 "2019-09-06T09:26:57Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![manish\_kakoti](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/manish_kakoti/32/53285_2.png) [@manish\_kakoti](https://discuss.elastic.co/u/manish_kakoti)
#### Post date: [September 6, 2019, 9:26am UTC](https://discuss.elastic.co/t/is-there-a-way-to-search-on-parent-fields-from-a-nested-query/198385/1 "2019-09-06T09:26:57Z")

</div>

I wrote a query which works well on nested fields, but also wanted to add a functionality where it can search on the parent fields as well.

Here is the mapping:

```auto
mapping: {
   doc: {
     properties: {
        "name" : {"type":"text"},
       "address": {"type": "text"}
      "interests": {"type": "nested","properties": {"game":{"type":"text" }}}
}

```

i can do a nested query on it, but unable to query parent from the nested query (i.e name and address). If there is a way to do it, can somebody help?

The vice versa will also help, where from parent we can also query nested docs

---

<div class="post-metadata">

### Author: ![Mikhail\_Khludnev](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/mikhail_khludnev/32/59591_2.png) [@Mikhail\_Khludnev](https://discuss.elastic.co/u/Mikhail_Khludnev)
#### Post date: [September 6, 2019, 10:42am UTC](https://discuss.elastic.co/t/is-there-a-way-to-search-on-parent-fields-from-a-nested-query/198385/2 "2019-09-06T10:42:48Z")

</div>

Hello, Manish.  
You can combine parent field query and nested one with bool/must.

---

<div class="post-metadata">

### Author: ![manish\_kakoti](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/manish_kakoti/32/53285_2.png) [@manish\_kakoti](https://discuss.elastic.co/u/manish_kakoti)
#### Post date: [September 6, 2019, 10:53am UTC](https://discuss.elastic.co/t/is-there-a-way-to-search-on-parent-fields-from-a-nested-query/198385/3 "2019-09-06T10:53:48Z")

</div>

Hi @Mikhail_Khludnev

I tried using must like this:

```auto
{
    "query": {
      "bool": {
        "must": [{
          "query": {
            "query_string": {
              "query": "test.pdf"
            }
          },
            "nested": {
              "path": ["files"],
              "query": {
                "query_string": {
                  "query": "test.pdf"
                }
              }
            }
            
          }]
          
          
      }
    }
}

```

But does not give me expected results, as test.pdf is a nested field, the query is coming in as dynamic string

---

<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: [October 4, 2019, 10:53am UTC](https://discuss.elastic.co/t/is-there-a-way-to-search-on-parent-fields-from-a-nested-query/198385/4 "2019-10-04T10:53:48Z")

</div>

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