-
问题一: 查询结果中 hits.total.value 值最大为10000的限制
解决方法:
请求时设置"track_total_hits": true
- Rest 请求设置方法:
curl -X POST "http://192.168.1.101:9200/my_index/_search?pretty" -H 'Content-Type: application/json' -d' { "track_total_hits": true "query": { "match_all": {} }, "sort": [ { "timestamp": { "order": "desc" } } ] } '
- API 设置方法:
SearchSourceBuilder searchSourceBuilder = new SearchSourceBuilder().trackTotalHits(true);
-
问题二: 分页查询 from 大于 10000 时的数据异常
异常信息
... Caused by: ElasticsearchException[Elasticsearch exception [type=illegal_argument_exception, reason=Result window is too large, from + size must be less than or equal to: [10000] but was [10100]. See the scroll api for a more efficient way to request large data sets. This limit can be set by changing the [index.max_result_window] index level setting.]]; nested: ElasticsearchException[Elasticsearch exception [type=illegal_argument_exception, reason=Result window is too large, from + size must be less than or equal to: [10000] but was [10100]. See the scroll api for a more efficient way to request large data sets. This limit can be set by changing the [index.max_result_window] index level setting.]]; ...
解决方法:
修改 max_result_window 设置的最大索引值,注意以 put 方式提交curl -X PUT "http://192.168.1.101:9200/my_index/_settings?pretty" -H 'Content-Type: application/json' -d' { "index":{ "max_result_window":1000000 } } '
网友评论