ElasticSearch (search_context_missing_exception) with Search::ElasticSearch::Scroll
The first thing that comes to mind is that the timer is not updated. Have you checked this? You can do a query every 10 seconds for example and see if at the 6th query it gives you the error ...
Well, a good rule of thumb is inside a ->next()
block, don't stay by iteration more than time that you've configured in scroll.
Between each call of ->next()
you cannot stay more than that time configured. If you stay more, the scroll may be not be there and the error earch_context_missing_exception
will appear.
My solution for this problem was inside next block only store data into array/hash structure and once the scroll process ended work with all data.
The solution of the question example:
# Retrieve scroll my $scroll = $self->getScrollBySignature($item); # Retrieve all affected documents ids my @allDocs; while (my @docs = $scroll->next(500)) { push @allDocs, map {$_->{_id}} @docs } foreach (@allDocs) { # Do stuff with doc }