# 'And' effect search for multiple nested object

**URL:** https://discuss.elastic.co/t/and-effect-search-for-multiple-nested-object/111148
**Category:** Elasticsearch
**Created:** [December 11, 2017, 5:01pm UTC](https://discuss.elastic.co/t/and-effect-search-for-multiple-nested-object/111148 "2017-12-11T17:01:28Z")
**Posts on this page:** 1
**Showing post:** 2

<div class="post-metadata">

### Author: ![johntadd](https://avatars.discourse-cdn.com/v4/letter/j/ecae2f/32.png) [@johntadd](https://discuss.elastic.co/u/johntadd)
#### Post date: [December 12, 2017, 10:57am UTC](https://discuss.elastic.co/t/and-effect-search-for-multiple-nested-object/111148/2 "2017-12-12T10:57:50Z")

</div>

Come across the the link - [Querying a multiple level nested object](https://discuss.elastic.co/t/querying-a-multiple-level-nested-object/56889). That basically helps solve my problem.

Instead of separated paths on different nested object query,

```
{
    "query": {
        "bool": {
            "must": [
                { ... nested query on path1 }
                { ... nested query on path2 }
            ]
        }
    }
}

```

query should be specified with base path then down to the deeper level. So each level can specify its own condition.

```
"query": {
    "nested": {
        "path": "level1tag.level2tag.level3tag",
        "query": {
            "bool": {
                "must": [
                    {
                        "term": { "level1tag.level2tag.level3tag.level3_attr1": "value A" }
                    },
                    {
                        "nested": {
                            "path": "level1tag.level2tag.level3tag.level4tag",
                            "query": {
                                "bool": {
                                     "must" : [
                                         { "term": { "level1tag.level2tag.level3tag.level4tag.level4_attr1" : "value B"} }
                                      ]
                                }
                            } 
                        }    
                    }
                ]
            }
        }
    }
}
```

---

_[View the full topic](https://discuss.elastic.co/t/and-effect-search-for-multiple-nested-object/111148)._
