# Multi-level nested query structure — bug or feature

**URL:** <https://discuss.elastic.co/t/multi-level-nested-query-structure-bug-or-feature/343475>\
**Category:** Elasticsearch\
**Tags:** eql-elastic-query-language\
**Created:** [September 20, 2023, 3:42pm UTC](https://discuss.elastic.co/t/multi-level-nested-query-structure-bug-or-feature/343475 "2023-09-20T15:42:00Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![jonnyeom](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/jonnyeom/32/125851_2.png) [@jonnyeom](https://discuss.elastic.co/u/jonnyeom)\
**Post date:** [September 20, 2023, 3:42pm UTC](https://discuss.elastic.co/t/multi-level-nested-query-structure-bug-or-feature/343475/1 "2023-09-20T15:42:00Z")

</div>

Hello, Im working with multi-level nested query filters.

Documentation in [Nested query | Elasticsearch Guide [8.10] | Elastic](https://www.elastic.co/guide/en/elasticsearch/reference/8.10/query-dsl-nested-query.html#multi-level-nested-query-ex)  
shows an example where each level is nested as part of the search query. i.e.  
**Query Example 1**

```json
GET /drivers/_search
{
  "query": {
    "nested": {
      "path": "driver",
      "query": {
        "nested": {
          "path": "driver.vehicle",
          "query": {
            "bool": {
              "must": [
                { "match": { "driver.vehicle.make": "Powell Motors" } },
                { "match": { "driver.vehicle.model": "Canyonero" } }
              ]
            }
          }
        }
      }
    }
  }
}

```

I can get the same result without nesting the query itself (hard to describe but example below)  
**Query Example 2**

```json
GET /drivers/_search
{
  "query": {
    "nested": {
      "path": "driver.vehicle",
      "query": {
        "bool": {
          "must": [
            { "match": { "driver.vehicle.make": "Powell Motors" } },
            { "match": { "driver.vehicle.model": "Canyonero" } }
          ]
        }
      }
    }
  }
}

```

The response for both

```json
// Note: this data is from the nested query documentation linked above.
{
  "took": 1,
  "timed_out": false,
  "_shards": {
    "total": 1,
    "successful": 1,
    "skipped": 0,
    "failed": 0
  },
  "hits": {
    "total": {
      "value": 1,
      "relation": "eq"
    },
    "max_score": 3.7349272,
    "hits": [
      {
        "_index": "drivers",
        "_id": "1",
        "_score": 3.7349272,
        "_source": {
          "driver": {
            "last_name": "McQueen",
            "vehicle": [
              {
                "make": "Powell Motors",
                "model": "Canyonero"
              },
              {
                "make": "Miller-Meteor",
                "model": "Ecto-1"
              }
            ]
          }
        }
      }
    ]
  }
}

```

## Question

- What is the difference between how elastic handles the 2 queries? ( I am assuming that seeing that there arent any other query conditions, it is the same).
- Is it a bug or feature that we can search directly into a deeply nested path (like example 2)? If a feature, I would like to add to the documentation to show this.

Appreciate it!  
Jonathan

---

<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 18, 2023, 3:42pm UTC](https://discuss.elastic.co/t/multi-level-nested-query-structure-bug-or-feature/343475/2 "2023-10-18T15:42:42Z")

</div>

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