Multi-level nested query structure — bug or feature

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

Documentation in Nested query | Elasticsearch Guide [8.10] | Elastic
shows an example where each level is nested as part of the search query. i.e.
Query Example 1

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

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

// 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

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