Elasticsearch 使用scroll时出现异常 Trying to create more than 500 scroll contexts will not be allowed

简述

Trying to create more than 500 scroll contexts will not be allowed in the next major version by default
 You can change the  [search.max_open_scroll_context] setting to use a greater default value or lower the number of scrolls that you need to run in parallel."

问题原因

Elasticsearch 使用scroll时,中设置的timeout时间内,累计生成的scroll_id数超过了最大限制

问题解决方式

  • 减小timeout设置
 SearchSourceBuilder searchSourceBuilder = new SearchSourceBuilder();
            searchSourceBuilder.query(queryBuilder);
            searchSourceBuilder.size(5000);
            SearchRequest searchRequest = new SearchRequest();
            searchRequest.source(searchSourceBuilder);
            TimeValue timeValue = new TimeValue(3000);
            searchRequest.scroll(timeValue);
            searchRequest.indices("");
  • 清理scroll
 ClearScrollRequest clearScrollRequest = new ClearScrollRequest();
                clearScrollRequest.addScrollId(scrollId);// 也可以选择setScrollIds()将多个scrollId一起使用
                ClearScrollResponse clearScrollResponse = null;
                try {
                    clearScrollResponse = produceRestClient.clearScroll(clearScrollRequest, RequestOptions.DEFAULT);
                } catch (IOException e) {
                    e.printStackTrace();
                }
                boolean succeeded = clearScrollResponse.isSucceeded();
                log.info("--------------->>>>{}-----", succeeded);
上一篇:VS2008压力测试时web测试记录器无显示


下一篇:如何查看操作系统的块大小