我需要获得脚本化指标聚合的热门文章

时间:2019-02-19 10:30:50

标签: elasticsearch

POST smartcontract_index/smartcontract_type/_search
{
  "size": 0,
  "query": {
    "nested": {
      "path": "items",
      "query": {
        "bool": {
          "must": [
            {
              "exists": {
                "field": "items"
              }
            }
          ]
        }
      }
    }
  },
  "aggs": {
    "delayed_m": {
      "scripted_metric": {
        "init_script": "params._agg.transactions = []",
        "map_script": "params.max = 0; for(item in params._source.items){ if(item.deliveryLeadTime != null && item.deliveryLeadTime > params.max){params.max = item.deliveryLeadTime }}   params.delayed = ((params._source.expirationDate + 86400000) - params.max*24*60*60*1000 - new Date().getTime()) < 0; params._agg.transactions.add(params.delayed)",
        "combine_script": "params.sum = 0; for (max in params._agg.transactions) { if(max)params.sum += 1 } return params.sum",
        "reduce_script": "params.sum =0; for(max in params._aggs){params.sum += max} return params.sum"
      }
    }
  }
}

上下文-------这是我在查询中使用脚本化指标的情况,我想要该脚本化指标结果中的热门结果,而我希望该热门结果

0 个答案:

没有答案