Elaasticsearch query to compare a filed value of 2 documents in same index

I have written below query to fetch latest two document to get few fields like #processor, allocated_memory for a particular server.
I want to extend the query to compare these fields i.e. #processor, allocated_memory for the 2 filtered documents and return the difference value.

"query": {
"term": {
"servername.keyword": {
"value": "prod01"
}
}
},
"size": 2,
"sort": [
{
"logtime": {
"order": "desc"
}
}
],
"_source":{
"includes":["logtime","#processors","allocated_memory_mb"]
}

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