How to resolve Trying to create too many scroll contexts. Must be less than or equal to: [500]?

Viewed 5414

I'm trying to query from Elastic DB. So for 90000 Records I need to hit elastic DB for two different occasions.My query is as follows.

    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;

While trying to exectue this, I'm getting error like :

 { 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.',

Can anybody help me how to fix this error?

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

Whenever you want to close the scroll api and open another scroll api, please run the above code. It works fine for me.

Related