微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

【Elasticsearch Postman版】聚合操作分组,平均值

1.请求方式:GET

2.请求URL: 

http://127.0.0.1:9200/shopping/_search

3.请求参数:

(1)分组

{
    "aggs" : { // 聚合操作
        "price_group" : { // 统计结果名称
            "terms" : { // 分组
                "field" : "price" // 分组字段
            }
        }
    },
    "size": 0

}

(2)求平均值

{
    "aggs" : { // 聚合操作
        "price_avg" : { // 统计结果名称
            "avg" : { // 求平均值
                "field" : "price" // 求平均值字段
            }
        }
    },
    "size": 0
}

4. 响应信息:

(1) 分组

{
    "took": 147,
    "timed_out": false,
    "_shards": {
        "total": 1,
        "successful": 1,
        "skipped": 0,
        "Failed": 0
    },
    "hits": {
        "total": {
            "value": 9,
            "relation": "eq"
        },
        "max_score": null,
        "hits": []
    },
    "aggregations": {
        "price_group": {
            "doc_count_error_upper_bound": 0,
            "sum_other_doc_count": 0,
            "buckets": [
                {
                    "key": 9999.0,
                    "doc_count": 3
                },
                {
                    "key": 2999.0,
                    "doc_count": 1
                },
                {
                    "key": 3999.0,
                    "doc_count": 1
                },
                {
                    "key": 4999.0,
                    "doc_count": 1
                },
                {
                    "key": 5999.0,
                    "doc_count": 1
                },
                {
                    "key": 6999.0,
                    "doc_count": 1
                },
                {
                    "key": 8999.0,
                    "doc_count": 1
                }
            ]
        }
    }
}

 

(2)求平均值

{
    "took": 1,
    "timed_out": false,
    "_shards": {
        "total": 1,
        "successful": 1,
        "skipped": 0,
        "Failed": 0
    },
    "hits": {
        "total": {
            "value": 9,
            "relation": "eq"
        },
        "max_score": null,
        "hits": []
    },
    "aggregations": {
        "price_avg": {
            "value": 7110.111111111111
        }
    }
}

 

 

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。

相关推荐