java命定指定类名启动,es7.x版本如何获取查询命中的文档总数

#### 前言

早在elasticsearch6.x版本时,es查询时默认会显示hits total总数,当然聚合场景下是不会的。目前我们项目将es6.8升级到7.6,一些普通查询,总数显示不正常了,最大只显示10000条。

比如查询语句如下:

```json

GET bd_frequent_test/_search

{

"query": {

"match_all": {}

}

}

```

查询结果如下:

```json

{

"took": 1,

"timed_out": false,

"_shards": {

"total": 20,

"successful": 20,

"skipped": 0,

"failed": 0

},

"hits": {

"total": {

"value": 10000,

"relation": "gte"

},

"max_score": 1.0,

"hits": [{

"_index": "bd_frequent_test",

"_type": "_doc",

"_id": "33030011",

"_score": 1.0,

"_routing": "506030",

"_source": {

"ape_id": "81",

"appear_num": 1,

"create_time": "2019-11-18 01:04:39",

"event_time": "2019-11-18",

"id": 33030011,

"last_event_time": "2019-11-18 01:04:39",

"pid": "506030",

"storage_date": "2019-11-18"

}

}]

}

}

```

es7版本只显示10000条总数,而实际命中文档数应该是100000000。

#### 解决办法

原因是7做了修改,默认最大只命中10000条,如果要让普通查询显示出全部命中的文档数,需要在查询中设置:

"track_total_hits":true

语句如下:

```json

GET bd_frequent_test/_search

{

"query": {

"match_all": {}

},

"track_total_hits":true

}

```

显示结果:

```json

{

"took": 1,

"timed_out": false,

"_shards": {

"total": 20,

"successful": 20,

"skipped": 0,

"failed": 0

},

"hits": {

"total": {

"value": 100000000,

"relation": "eq"

},

"max_score": 1.0,

"hits": [{

"_index": "bd_frequent_test",

"_type": "_doc",

"_id": "33030011",

"_score": 1.0,

"_routing": "506030",

"_source": {

"ape_id": "81",

"appear_num": 1,

"create_time": "2019-11-18 01:04:39",

"event_time": "2019-11-18",

"id": 33030011,

"last_event_time": "2019-11-18 01:04:39",

"pid": "506030",

"storage_date": "2019-11-18"

}

}]

}

}

```

命中数就会显示出实际查询命中的文档数了。

hits响应体如下:

```json

"total": {

"value": 100000000,

"relation": "eq"

}

```

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值