ElasticSearch聚合查询

ElasticSearch聚合查询

1.group distinct

参数:Set

返回结果:Map<Long, Set>

select distinct(playCategory) group by uid

{
    "query":{
        "bool":{
            "filter":[
                {
                    "terms":{
                        "guid":[
                            "1835212105600007",
                            "1835212121800011"
                        ],
                        "boost":1
                    }
                }
            ],
            "adjust_pure_negative":true,
            "boost":1
        }
    },
    "_source":{
        "includes":[
            "playCategory.keyword"
        ],
        "excludes":[

        ]
    },
    "aggregations":{
        "group_info":{
            "terms":{
                "field":"guid",
                "size":10,/*group_info 的 limit*/
                "min_doc_count":1,
                "shard_min_doc_count":0,
                "show_term_doc_count_error":false,
                "order":[
                    {
                        "_count":"desc"
                    },
                    {
                        "_key":"asc"
                    }
                ]
            },
            "aggregations":{
                "distinct_info":{
                    "terms":{
                        "field":"playCategory.keyword",
                        "size":10,/*distinct_info的limit*/
                        "min_doc_count":1,
                        "shard_min_doc_count":0,
                        "show_term_doc_count_error":false,
                        "order":[
                            {
                                "_count":"desc"
                            },
                            {
                                "_key":"asc"
                            }
                        ]
                    }
                }
            }
        }
    }
}

查询结果如下

{
    "took":2,
    "timed_out":false,
    "_shards":{
        "total":5,
        "successful":5,
        "skipped":0,
        "failed":0
    },
    "hits":{
        "total":139,
        "max_score":0,
        "hits":[
            {
                "_index":"bixin_playmate_order",
                "_type":"bixin_playmate_order",
                "_id":"42515235",
                "_score":0,
                "_source":{

                }
            },
            {
                "_index":"bixin_playmate_order",
                "_type":"bixin_playmate_order",
                "_id":"50943600",
                "_score":0,
                "_source":{

                }
            },
            {
                "_index":"bixin_playmate_order",
                "_type":"bixin_playmate_order",
                "_id":"50943796",
                "_score":0,
                "_source":{

                }
            },
            {
                "_index":"bixin_playmate_order",
                "_type":"bixin_playmate_order",
                "_id":"42514238",
                "_score":0,
                "_source":{

                }
            },
            {
                "_index":"bixin_playmate_order",
                "_type":"bixin_playmate_order",
                "_id":"42514231",
                "_score":0,
                "_source":{

                }
            },
            {
                "_index":"bixin_playmate_order",
                "_type":"bixin_playmate_order",
                "_id":"50943123",
                "_score":0,
                "_source":{

                }
            },
            {
                "_index":"bixin_playmate_order",
                "_type":"bixin_playmate_order",
                "_id":"42514354",
                "_score":0,
                "_source":{

                }
            },
            {
                "_index":"bixin_playmate_order",
                "_type":"bixin_playmate_order",
                "_id":"42515407",
                "_score":0,
                "_source":{

                }
            },
            {
                "_index":"bixin_playmate_order",
                "_type":"bixin_playmate_order",
                "_id":"50942086",
                "_score":0,
                "_source":{

                }
            },
            {
                "_index":"bixin_playmate_order",
                "_type":"bixin_playmate_order",
                "_id":"50942161",
                "_score":0,
                "_source":{

                }
            }
        ]
    },
    "aggregations":{
        "group_info":{
            "doc_count_error_upper_bound":0,
            "sum_other_doc_count":0,
            "buckets":[
                {
                    "key":1835212121800011,
                    "doc_count":79,
                    "distinct_info":{
                        "doc_count_error_upper_bound":0,
                        "sum_other_doc_count":2,
                        "buckets":[
                            {
                                "key":"d2525eb038dfcf29ae1d3d2eb65d076c",
                                "doc_count":32
                            },
                            {
                                "key":"c",
                                "doc_count":25
                            },
                            {
                                "key":"b2f36bbf94624eda70367bb5146e8bcf",
                                "doc_count":13
                            },
                            {
                                "key":"b2f36bbf94624eda70367bb5146e8bc1",
                                "doc_count":1
                            },
                            {
                                "key":"b2f36bbf94624eda70367bb5146e8bc2",
                                "doc_count":1
                            },
                            {
                                "key":"b2f36bbf94624eda70367bb5146e8bc3",
                                "doc_count":1
                            },
                            {
                                "key":"b2f36bbf94624eda70367bb5146e8bc4",
                                "doc_count":1
                            },
                            {
                                "key":"b2f36bbf94624eda70367bb5146e8bc5",
                                "doc_count":1
                            },
                            {
                                "key":"b2f36bbf94624eda70367bb5146e8bc6",
                                "doc_count":1
                            },
                            {
                                "key":"b2f36bbf94624eda70367bb5146e8bc7",
                                "doc_count":1
                            }
                        ]
                    }
                },
                {
                    "key":1835212105600007,
                    "doc_count":60,
                    "distinct_info":{
                        "doc_count_error_upper_bound":0,
                        "sum_other_doc_count":0,
                        "buckets":[
                            {
                                "key":"bf78dd67d648dc541dff0dc86f8af718",
                                "doc_count":38
                            },
                            {
                                "key":"d2525eb038dfcf29ae1d3d2eb65d076c",
                                "doc_count":14
                            },
                            {
                                "key":"471028758308978688",
                                "doc_count":4
                            },
                            {
                                "key":"b2f36bbf94624eda70367bb5146e8bcf",
                                "doc_count":4
                            }
                        ]
                    }
                }
            ]
        }
    }
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值