es查询超过一万条就报错了

Caused by: org.elasticsearch.client.ResponseException: method [POST],typed_keys=true&ignore_unavailable=false&expand_wildcards=open&allow_no_indices=true&search_type=query_then_fetch&batched_reduce_size=512], status line [HTTP/1.1 500 Internal Server Error]
{“error”:{“root_cause”:[{“type”:“query_phase_execution_exception”,“reason”:“Result window is too large, from + size must be less than or equal to: [10000] but was [10500]. 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.”}],“type”:“search_phase_execution_exception”,“reason”:“all shards failed”,“phase”:“query”,“grouped”:true,“failed_shards”:[{“shard”:0,“index”:“merchant”,“node”:“eFgcmK_iTse5mwHoPOwirg”,“reason”:{“type”:“query_phase_execution_exception”,“reason”:“Result window is too large, from + size must be less than or equal to: [10000] but was [10500]. 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.”}}]},“status”:500}
at org.elasticsearch.client.RestClient$1.completed(RestClient.java:552)

解决方法
{
“index”:{
“max_result_window”:1000000
}
}
将es索引该属性增加,不过该属性增加会影响es性能。es作为搜索引擎,最好不要分页查询。

不过可以利用scroll遍历数据

scroll查询原理是在第一次查询的时候一次性生成一个快照,根据上一次的查询的id来进行下一次的查询,这个就类似于关系型数据库的游标,然后每次滑动都是根据产生的游标id进行下一次查询,这种性能比上面说的分页性能要高出很多,基本都是毫秒级的。 注意:scroll不支持跳页查询。 使用场景:对实时性要求不高的查询,例如微博或者头条滚动查询。 具体java代码实现

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值