桶脚本聚合-弹性搜索

时间:2020-09-29 19:47:48

标签: elasticsearch elastic-stack kibana-7

我正在尝试在Elastic Search上构建查询,以获取两个值的差异:

这是我正在使用的代码:

GET /monitora/_search
{
  "size":0,
  "aggs": {
    "CALC_DIFF": {
      "filters": {
        "filters": {
          "FTS_callback": {"term":{ "msgType": "panorama_fts"}},
          "FTS_position": {"term":{ "msgType": "panorama_position"}}
                  }
                },
        "aggs": {
          "subtract": {
            "bucket_script": {
              "buckets_path": {
                "PCountCall": "_count",
                "PcountPos":"_count"
              },
              "script": "params.PCountCall - params.PcountPos"
            }
          }
        }
      }
 }
}

这是我运行它后得到的结果:

{
  "took" : 0,
  "timed_out" : false,
  "_shards" : {
    "total" : 5,
    "successful" : 5,
    "skipped" : 0,
    "failed" : 0
  },
  "hits" : {
    "total" : {
      "value" : 10000,
      "relation" : "gte"
    },
    "max_score" : null,
    "hits" : [ ]
  },
  "aggregations" : {
    "CALC_DIFF" : {
      "buckets" : {
        "FTS_callback" : {
          "doc_count" : 73530,
          "subtract" : {
            "value" : 0.0
          }
        },
        "FTS_position" : {
          "doc_count" : 156418,
          "subtract" : {
            "value" : 0.0
          }
        }
      }
    }
  }
}

但是,我没有在这些存储桶中进行减法运算(该运算符始终为零),而是在寻找每个存储桶的计数减法,因此在此示例之后将返回我(73530-156418)。

之后,我想在Kibana中将结果显示为“度量”可视化元素。有可能吗?

有人能帮我把事情弄清楚吗?

谢谢!

0 个答案:

没有答案