美文网首页
ES常用聚合命令

ES常用聚合命令

作者: 不怕天黑_0819 | 来源:发表于2021-05-28 10:38 被阅读0次

    Count聚合(统计个数)

    GET /subscribe_content_manage/content_manage_info/_search
    {
        "query" : {
          "range": {
            "createTime": {
              "gte": "now-10d"
    
            }
          }},
       "size" : 0,
       "aggs": {
          "grades_contentState": {
            "value_count": {
              "field": "contentState"
            }
          }
       }
    }
    
    return:
    
    {
      "took": 2,
      "timed_out": false,
      "_shards": {
        "total": 6,
        "successful": 6,
        "failed": 0
      },
      "hits": {
        "total": 200,
        "max_score": 0,
        "hits": []
      },
      "aggregations": {
        "grades_contentState": {
          "value": 200
        }
      }
    }
    

    Avg Aggregations

    GET /subscribe_content_manage/content_manage_info/_search
    {
        "query" : {
          "range": {
            "createTime": {
              "gte": "now-10d"
    
            }
          }},
       "size" : 0,
       "aggs": {
          "grades_contentState": {
            "avg": {
              "field": "contentState"
            }
          }
       }
    }
    
    return:
    {
      "took": 2,
      "timed_out": false,
      "_shards": {
        "total": 6,
        "successful": 6,
        "failed": 0
      },
      "hits": {
        "total": 200,
        "max_score": 0,
        "hits": []
      },
      "aggregations": {
        "grades_contentState": {
          "value": 2.965
        }
      }
    }
    

    sum aggregation(求和)

    GET /subscribe_content_manage/content_manage_info/_search
    {
        "query" : {
          "range": {
            "createTime": {
              "gte": "now-1d"
    
            }
          }},
       "size" : 0,
       "aggs": {
          "grades_contentState": {
            "value_count": {
              "field": "contentState"
            }
          }
       }
    }
    
    {
      "took": 3,
      "timed_out": false,
      "_shards": {
        "total": 6,
        "successful": 6,
        "failed": 0
      },
      "hits": {
        "total": 36,
        "max_score": 0,
        "hits": []
      },
      "aggregations": {
        "grades_contentState": {
          "value": 36
        }
      }
    }
    

    相关文章

      网友评论

          本文标题:ES常用聚合命令

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