Is there any way to search for only one element from an array?

Hello Everyone,

I am searching for any suggestions that would get me only one element from an array in Elasticsearch index.

I have tried the composite aggregation, nested aggregation and nested query but all of these approaches returns all the elements of an array.

lets say i have a field named "parameters" and it has other nested fields such as "ID" and "Value".
The documents looks like:

"parameters": [
{
"ID": 101,
"Value": 0.25
},
{
"ID": 102,
"Value": 0.38
}
]

so i would like to get the data from a "value" field with "ID": 101.
The answer should be 0.25. But i am getting all the data from the array including 0.38 which is irrelevant.

The Query i used is:

GET test_index/_search
{
"query" : {
"match" : { "ID" : "101" }
},
"aggs":{
"comp":{
"composite": {
"size" : 10000,
"sources": [
{
"name": { "terms": {"field":"name.keyword"} }
},
{
"speed": { "terms": { "field": "parameters.Value"} }
}
]
}
}
}
}

Any suggestions would be very much appreciated.

Best Regards,
Nirajan

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