网上关于Spring-Data-Elasticsearch的Scroll API资料有点少,今天我也遇到了这个困难,现在解决了,本着人人为我,我为人人的想法,整理于此,供遇到同样困难的同学参考
Exception[Result window is too large, from + size must be less than or equal to: [10000] but was [58000]. 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 parameter.]
可以看出,异常信息提示我们请求大数据量的情况下使用Scroll API。
在网上搜索后,发现博客,总结于此,供参考
参考博客1:springBoot集成es查询,使用ElasticsearchTemplate执行滚动查询
参考博客2:Spring集成elasticSearch,使用elasticTemplate的scroll查询分页拉取全量数据
从这两篇博客可以看出,针对此问题,我们就是使用ElasticsearchTemplate类的 startScroll 方法,它有几个不同的重载,我这里选择最简单的一个。
还有两个方法,一个是continueScroll方法,一个是clearScroll方法。
下面附上我的测试代码,也是参考上面两篇博客里的
@Te