I want to search an object on only the first element in an array and ignore the rest.
For example, for data below if I wanted to only search the model
for the first element in the vehicle
array.
{
"drivers" : [
{
"last_name" : "McQueen",
"vehicle" : [
{
"make" : "Powell Motors",
"model" : "Canyonero"
},
{
"make" : "Miller-Meteor",
"model" : "Ecto-1"
}
]
},
{
"last_name" : "Buzz",
"vehicle" : [
{
"make" : "Powell Motors",
"model" : "Canyonero"
},
{
"make" : "Miller-Meteor",
"model" : "Ecto-1"
}
]
}
}
I know I can do a nested query like this but the problem here is that all the vehicles are searched. I only want the 0th element in the vehicle list to be searched and the rest to be ignored.
{
"query": {
"nested": {
"path": "driver",
"query": {
"nested": {
"path": "driver.vehicle",
"query": {
"bool": {
"must": [
{ "match": { "drivers.vehicle.model": "Canyonero" } }
]
}
}
}
}
}
}
}
Ideally I want something like { drivers.vehicle[0].model": "Canyonero" }
to search for the first vehicle in the list everytime. Is there any way I can effectively do this?