I'm not sure if you can get a sub-array from a document.
However, one way to achieve this is to use nested fields. You can change the field diagram followinglike nestedas shown below.
{
"id": "3330481",
"following": [
{"userId":"1"}, {"userId":"2"},{"userId": "3"}, ... ]
}
inner_hits, , .
{
"query" : {
"nested" : {
"path" : "following",
"query" : {
"terms" : {"following.userId" : ["50","51","53"]}
},
"inner_hits" : {
"size":0 // fetches all
}
}
}
}