解决ES中查询结果超过10000条报错

在ES中查询结果超过10000条的时候,会报出如下错误:

{
    "error": {
        "root_cause": [
            {
                "type": "query_phase_execution_exception",
                "reason": "Result window is too large, from + size must be less than or equal to: [1000000] but was [10000010]. 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."
            }
        ],
        "type": "search_phase_execution_exception",
        "reason": "all shards failed",
        "phase": "query",
        "grouped": true,
        "failed_shards": [
            {
                "shard": 0,
                "index": "results",
                "node": "JwHV4B5VSN-F9US2cNmXZA",
                "reason": {
                    "type": "query_phase_execution_exception",
                    "reason": "Result window is too large, from + size must be less than or equal to: [1000000] but was [10000010]. 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."
                }
            }
        ]
    },
    "status": 500
}

默认只能查到一万条,将该设置增大即可。

解决方法:

curl -XPUT http://127.0.0.1:9200/results/_settings -d '{ "index" : { "max_result_window" : 1000000}}'

注意:上面url中的results换成自己的index名称

或者在postman中发送put请求也可以。报文如下:

{ "index" : { "max_result_window" : 1000000}}
  • 2
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 2
    评论
在Java使用ES查询时,如果查询结果总数超过10000ES默认只返回前10000结果。如果想要获取所有结果,可以使用scroll API实现滚动查询。 下面是一个简单的示例代码,演示如何使用JavaES查询总数超过10000的情况: ``` SearchRequestBuilder searchRequestBuilder = client.prepareSearch(indexName) .setTypes(typeName) .setQuery(queryBuilder) .setSize(1000) //一次获取1000数据 .setScroll(new TimeValue(60000)); //设置滚动时间间隔 SearchResponse searchResponse = searchRequestBuilder.execute().actionGet(); long totalCount = searchResponse.getHits().getTotalHits(); while (true) { searchResponse = client.prepareSearchScroll(searchResponse.getScrollId()) .setScroll(new TimeValue(60000)) //设置滚动时间间隔 .execute() .actionGet(); if (searchResponse.getHits().getHits().length == 0) { break; } //处理数据 } ``` 在上面的代码,我们首先执行一次查询,并获取查询结果总数。然后,我们使用scroll API实现滚动查询,设置滚动时间间隔为60秒。在每次循环,我们从ES获取1000数据并处理,直到滚动查询结束。 值得注意的是,scroll API会在ES服务器上保留查询状态,因此需要在处理完所有结果后手动清除查询状态,以释放ES服务器资源。可以使用以下代码清除查询状态: ``` ClearScrollRequest clearScrollRequest = new ClearScrollRequest(); clearScrollRequest.addScrollId(searchResponse.getScrollId()); client.clearScroll(clearScrollRequest); ```

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值