ElasticSearch仅统计数据的查询语句

实际应用中,有时候只是想统计符合条件的数据条数,并不需要返回详细数据,以加快数据传输。这时候可以设置"size": 0,表示不返回数据详情,DSL查询语句如下:

{
    "query": {
        "bool": {
            "must": [
                {
                    "match": {
                        "关键词": "值"
                    }
                }
            ],
            
        }
    },
    "size": 0
}

查询结果类似如下:

{
    "took": 26,
    "timed_out": false,
    "_shards": {
        "total": 14,
        "successful": 14,
        "skipped": 0,
        "failed": 0
    },
    "hits": {
        "total": 2387,
        "max_score": 0,
        "hits": [
            
        ]
    }
}

其中 hits下面的 total对应了满足要求的数据总数。

你可能感兴趣的:(Elasticsearch)