居然是你

按时间查重并去重统计

Elasticsearch | 作者 my_libl | 发布于2020年06月23日 | 阅读数:1712

ES7.3版本大神好,有一个需求按时间查询每小时的内容,关键字是test,然后在按client字段去重并且计数该怎么写啊,谢谢
时间字段 @timestamp
搜索的字段 url
需要统计的字段 client
{
            "query": {
                "bool": {
                    "must": [
                        {
                            "range": {
                                "@timestamp": {
                                    "format": "strict_date_optional_time",
                                    "gte": "2020-06-16T06:10:00.000Z",
                                    "lte": "2020-06-16T07:10:00.000Z"
                                }
                            }
                        }
                    ],
                    "filter": [
                        {
                            "bool": {
                                "should": [
                                    {
                                        "multi_match": {
                                            "type": "phrase",
                                            "query": "test“,
                                            "lenient": 'true'
                                        }
                                    }
                                ],
                                "minimum_should_match": 1
                            }
                        }
                    ],
                    "should": [],
                    "must_not": []
                }
            }, "_source": ["url", "@timestamp", "client"]
        }
已邀请:

FFFrp

赞同来自:

terms聚合

- Elasticsearch,php

赞同来自:

在query同一级,加一个collapse关键字的折叠字段,但是此时在hits里面计算处理的总数是不匹配的,需要通过aggs的cardinality去获取去重后的数量
 
"collapse": {
"field": "client"
},

pony_maggie - 公众号:犀牛饲养员的技术笔记

赞同来自:

用cardinality去重统计,不过要注意精度的问题,使用precision_threshold控制精度

要回复问题请先登录注册