相关疑难解决方法(0)

单个查询以查找某些字段具有最大值的文档

我有一组具有唯一数字运行ID的文档,我想找到运行ID最高的文档.

我可以做两个查询.

首先,我可以找到最高运行ID:

{
    "size": 0,
    "aggregations": {
      "latest_run_id": {
        "aggregations": {
          "latest_run_id": {
            "max": {"field": "run_id"}
          }
        }
      }
    }
}
Run Code Online (Sandbox Code Playgroud)

其次,我可以找到运行id的文件:

{
    "filter": {
        {"term": {"run_id": latest_run_id}}
    }
}
Run Code Online (Sandbox Code Playgroud)

有没有办法用一个查询来做到这一点?

elasticsearch

16
推荐指数
2
解决办法
2万
查看次数

标签 统计

elasticsearch ×1