Nested query max value

For a set of documents like this:

{
"took" : 1,
"timed_out" : false,
"_shards" : {
"total" : 1,
"successful" : 1,
"skipped" : 0,
"failed" : 0
},
"hits" : {
"total" : {
"value" : 3,
"relation" : "eq"
},
"max_score" : 1.0,
"hits" : [
{
"_index" : "drivers",
"_type" : "_doc",
"_id" : "1",
"_score" : 1.0,
"_source" : {
"driver" : {
"last_name" : "McQueen",
"vehicle" : [
{
"make" : "Powell Motors",
"model" : "Canyonero",
"grade" : 23
},
{
"make" : "Miller-Meteor",
"model" : "Ecto-2",
"grade" : 2
}
]
}
}
},
{
"_index" : "drivers",
"_type" : "_doc",
"_id" : "2",
"_score" : 1.0,
"_source" : {
"driver" : {
"last_name" : "McQueen",
"vehicle" : [
{
"make" : "Powell Motors",
"model" : "Canyonero",
"grade" : 1
},
{
"make" : "Miller-Meteor",
"model" : "Ecto-1",
"grade" : 100
}
]
}
}
},
{
"_index" : "drivers",
"_type" : "_doc",
"_id" : "3",
"_score" : 1.0,
"_source" : {
"driver" : {
"last_name" : "McQueen",
"vehicle" : [
{
"make" : "Powell Motors",
"model" : "Canyonero",
"grade" : 72
},
{
"make" : "Miller-Meteor",
"model" : "Ecto-1",
"grade" : 46
}
]
}
}
}
]
}
}

How do I get all documents that field driver.vehicle.make "Powell Motors" has the max grade in the array ? (It should return only doc 1 and doc 3)
I would like it will be executed in one query

Clear structure:

doc 1 :

"driver": {
  "last_name": "McQueen",
  "vehicle": [
    {
      "make": "Powell Motors",
      "model": "Canyonero",
      "grade": 23
    },
    {
      "make": "Miller-Meteor",
      "model": "Ecto-1",
      "grade": 2
    }
  ]
}

doc 2 :

 "driver": {
  "last_name": "McQueen",
  "vehicle": [
    {
      "make": "Powell Motors",
      "model": "Canyonero",
      "grade": 1
    },
    {
      "make": "Miller-Meteor",
      "model": "Ecto-1",
      "grade": 100
    }
  ]
}

doc 3 :

"driver": {
"last_name": "McQueen",
"vehicle": [
  {
    "make": "Powell Motors",
    "model": "Canyonero",
    "grade": 72
  },
  {
    "make": "Miller-Meteor",
    "model": "Ecto-1",
    "grade": 46
  }
]}

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