美文网首页
Elasticsearch Sum Aggregation

Elasticsearch Sum Aggregation

作者: 觉释 | 来源:发表于2020-10-09 16:48 被阅读0次

Sum Aggregation

POST /sales/_search?size=0
{
  "query": {
    "constant_score": {
      "filter": {
        "match": { "type": "hat" }
      }
    }
  },
  "aggs": {
    "hat_prices": { "sum": { "field": "price" } }
  }
}
返回值

{
  ...
  "aggregations": {
    "hat_prices": {
      "value": 450.0
    }
  }
}

Missing value

POST /sales/_search?size=0
{
  "query": {
    "constant_score": {
      "filter": {
        "match": { "type": "hat" }
      }
    }
  },
  "aggs": {
    "hat_prices": {
      "sum": {
        "field": "price",
        "missing": 100 
      }
    }
  }
}

Histogram fields

PUT metrics_index/_doc/1
{
  "network.name" : "net-1",
  "latency_histo" : {
      "values" : [0.1, 0.2, 0.3, 0.4, 0.5], 
      "counts" : [3, 7, 23, 12, 6] 
   }
}

PUT metrics_index/_doc/2
{
  "network.name" : "net-2",
  "latency_histo" : {
      "values" :  [0.1, 0.2, 0.3, 0.4, 0.5], 
      "counts" : [8, 17, 8, 7, 6] 
   }
}

POST /metrics_index/_search?size=0
{
  "aggs" : {
    "total_latency" : { "sum" : { "field" : "latency_histo" } }
  }
}

返回值

{
  ...
  "aggregations": {
    "total_latency": {
      "value": 28.8
    }
  }
}

相关文章

网友评论

      本文标题:Elasticsearch Sum Aggregation

      本文链接:https://www.haomeiwen.com/subject/ludjyktx.html