首页 > 解决方案 > 如何解决尝试创建太多滚动上下文。必须小于或等于:[500]?

问题描述

我正在尝试从 Elastic DB 进行查询。因此,对于 90000 条记录,我需要在两种不同的情况下使用弹性数据库。我的查询如下。

    var queryobj = {

    "query": {

        "bool": {

            "must": [

                {

                    "match": {

                        "mobile": value

                    }
                }

            ],

        }
    }

};
var { _scroll_id, hits, took } = await elasticClient.search({
    index: 'mobiledata',     
    type: '_doc',
    scroll: '20m',
    filterPath: '_scroll_id,hits.hits._source,took',
    size: 10000,
    body: queryobj
});

if (hits) {
    console.log("hits ", hits);
    return hits.hits;
}
return hits;

在尝试执行此操作时,我收到如下错误:

 { Error: [exception] Trying to create too many scroll contexts. Must be less than or equal to: 
 [500]. This limit can be set by changing the [search.max_open_scroll_context] setting.
 status: 500,
 displayName: 'InternalServerError',
 message: '[exception] Trying to create too many scroll contexts. Must be less than or equal to: 
 [500]. This limit can be set by changing the [search.max_open_scroll_context] setting.',

谁能帮我解决这个错误?

标签: node.jselasticsearch

解决方案


await elasticClient.clearScroll({scroll_id: _scroll_id});

每当您想关闭滚动 api 并打开另一个滚动 api 时,请运行上述代码。这对我来说可以。


推荐阅读