Selen Selen Asked:2020-11-02 04:28:25 +0000 UTC2020-11-02 04:28:25 +0000 UTC 2020-11-02 04:28:25 +0000 UTC 如何计算 Elasticsearch 中两个字段之间的差异? 772 在SQL中: SELECT lastTime - firstTime as result FROM times; Elasticsearch中的查询会是什么样子? elasticsearch 1 个回答 Voted Best Answer Andrey Morozov 2020-11-02T20:15:42Z2020-11-02T20:15:42Z 在请求中使用script_fields最简单 { "query" : { "match_all": {} }, "script_fields": { "result": { "script": "doc['lastTime'].value - doc['firstTime'].value" } } } 仅当两个字段都是整数或浮点类型时才会执行数学操作。否则,串联。检查映射。
在请求中使用script_fields最简单
仅当两个字段都是整数或浮点类型时才会执行数学操作。否则,串联。检查映射。