注: 部分概念介绍来源于网络

在使用es进行数据查询时,由于es官方默认限制了索引一次性最多只能查询10000条数据,查询第10001条数据开始就会报错,
错误的内容大致为:

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 requestlarge data sets. This limit can be set by changing the[index.max_result_window] index level parameter

方案1:在设置索引属性时解除索引最大查询数的限制

put _all/_settings
{
    "index.max_result_window":20000
}
_all表示所有索引,针对单个索引的话修改成索引名称即可

方案2:修改集群配置config/elasticsearch.yml 文件
增加如下配置

max_result_window: 20000

方案3:在创建索引的时候加上

"settings":{
    "index":{
        "max_result_window": 20000
    }
}

如果这样设置完毕之后还不行,这时候需要在API中添加一行代码:

searchSourceBuilder.trackTotalHits(true);

如果是使用kibana等工具的dsl语句,可以参考下面编写

GET 索引名/_search
{
    "query": {
        "match_all": {}
    },
    "track_total_hits":true
}

Logo

为开发者提供学习成长、分享交流、生态实践、资源工具等服务,帮助开发者快速成长。

更多推荐