es去重查询

{
    "query": {
                "bool": {
                    "must": [
                        {
                            "exists": {
                                "field": "vir_name"
                            }
                        },
                        {
                            "bool": {
                                "should": [
                                    {
                                        "regexp": {
                                            "vir_name.keyword": ".*\[prv.*"
                                        }
                                    },
                                    {
                                        "regexp": {
                                            "vir_name.keyword": ".*\[rmt.*"
                                        }
                                    }
                                ],
                                "minimum_should_match": 1
                            }
                        }
                    ],
                    "must_not": [
                        {
                            "match": {
                                "vir_name": "err"
                            }
                        },
                        {
                            "match": {
                                "imei": "err"
                            }
                        }
                    ]
                }
            },
    "aggs": {
                "imei": {
                    "terms": {
                        "field": "imei.keyword",
                        "size": 999
                    },
                    "aggs": {
                        "rated": {
                            "top_hits": {
                                "sort": [
                                    {
                                        "time.keyword": {
                                            "order": "desc"
                                        }
                                    }
                                ],
                                "size": 1
                            }
                        }
                    }
                }
            }
}
原文地址:https://www.cnblogs.com/paopao123/p/10749293.html