in SQL :

SELECT lastTime - firstTime as result FROM times; 

What will the query look like in Elasticsearch ?

    1 answer 1

    The easiest way is to use script_fields in a query.

     { "query" : { "match_all": {} }, "script_fields": { "result": { "script": "doc['lastTime'].value - doc['firstTime'].value" } } } 

    Mathematical action will be performed only if both fields are of type integer or float. Otherwise concatenation. Check mapping.