Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ElasticSearch (search_context_missing_exception) with Search::ElasticSearch::Scroll

I'm using Search::Elasticsearch and Search::Elasticsearch::Scroll for search and scroll into my elasticsearch server.

In scrolling process, for some querys, I'm seeing the next errors while I'm scrolling the search results:

2016/03/22 11:03:38 - 265885 FATAL: [Daemon.pm][8221]: Something gone wrong, error $VAR1 = bless( {
 'msg' => '[Missing] ** [http://localhost:9200]-[404] Not Found, called from sub Search::Elasticsearch::Scroll::next at searcher.pl line 92. With vars: {\'body\' => {\'hits\' => {\'hits\' => [],\'max_score\' => \'0\',\'total\' => 5215},\'timed_out\' => bless( do{\\(my $o = 0)}, \'JSON::XS::Boolean\' ),\'_shards\' => {\'failures\' => [{\'index\' => undef,\'reason\' => {\'reason\' => \'No search context found for id [4920053]\',\'type\' => \'search_context_missing_exception\'},\'shard\' => -1},{\'index\' => undef,\'reason\' => {\'reason\' => \'No search context found for id [5051485]\',\'type\' => \'search_context_missing_exception\'},\'shard\' => -1},{\'index\' => undef,\'reason\' => {\'reason\' => \'No search context found for id [4920059]\',\'type\' => \'search_context_missing_exception\'},\'shard\' => -1},{\'index\' => undef,\'reason\' => {\'reason\' => \'No search context found for id [5051496]\',\'type\' => \'search_context_missing_exception\'},\'shard\' => -1},{\'index\' => undef,\'reason\' => {\'reason\' => \'No search context found for id [5051500]\',\'type\' => \'search_context_missing_exception\'},\'shard\' => -1}],\'failed\' => 5,\'successful\' => 0,\'total\' => 5},\'_scroll_id\' => \'c2NhbjswOzE7dG90YWxfaGl0czo1MjE1Ow==\',\'took\' => 2},\'request\' => {\'serialize\' => \'std\',\'path\' => \'/_search/scroll\',\'ignore\' => [],\'mime_type\' => \'application/json\',\'body\' => \'c2Nhbjs1OzQ5MjAwNTM6bHExbENzRDVReEc0OV9UMUgzd3Vkdzs1MDUxNDg1OnJrQ3lsUkRKVHRxRWRWeURoOTB4WVE7NDkyMDA1OTpscTFsQ3NENVF4RzQ5X1QxSDN3dWR3OzUwNTE0OTY6cmtDeWxSREpUdHFFZFZ5RGg5MHhZUTs1MDUxNTAwOnJrQ3lsUkRKVHRxRWRWeURoOTB4WVE7MTt0b3RhbF9oaXRzOjUyMTU7\',\'qs\' => {\'scroll\' => \'1m\'},\'method\' => \'GET\'},\'status_code\' => 404}
',
 'stack' => [
              [
                'searcher.pl',
                92,
                'Search::Elasticsearch::Scroll::next'
              ]
            ],
 'text' => '[http://localhost:9200]-[404] Not Found',
 'vars' => {
             'body' => {
                         'hits' => {
                                     'hits' => [],
                                     'max_score' => '0',
                                     'total' => 5215
                                   },
                         'timed_out' => bless( do{\(my $o = 0)}, 'JSON::XS::Boolean' ),
                         '_shards' => {
                                        'failures' => [
                                                        {
                                                          'index' => undef,
                                                          'reason' => {
                                                                        'reason' => 'No search context found for id [4920053]',
                                                                        'type' => 'search_context_missing_exception'
                                                                      },
                                                          'shard' => -1
                                                        },
                                                        {
                                                          'index' => undef,
                                                          'reason' => {
                                                                        'reason' => 'No search context found for id [5051485]',
                                                                        'type' => 'search_context_missing_exception'
                                                                      },
                                                          'shard' => -1
                                                        },
                                                        {
                                                          'index' => undef,
                                                          'reason' => {
                                                                        'reason' => 'No search context found for id [4920059]',
                                                                        'type' => 'search_context_missing_exception'
                                                                      },
                                                          'shard' => -1
                                                        },
                                                        {
                                                          'index' => undef,
                                                          'reason' => {
                                                                        'reason' => 'No search context found for id [5051496]',
                                                                        'type' => 'search_context_missing_exception'
                                                                      },
                                                          'shard' => -1

                                                                                                        },
                                                        {
                                                          'index' => undef,
                                                          'reason' => {
                                                                        'reason' => 'No search context found for id [5051500]',
                                                                        'type' => 'search_context_missing_exception'
                                                                      },
                                                          'shard' => -1
                                                        }
                                                      ],
                                        'failed' => 5,
                                        'successful' => 0,
                                        'total' => 5
                                      },
                         '_scroll_id' => 'c2NhbjswOzE7dG90YWxfaGl0czo1MjE1Ow==',
                         'took' => 2
                       },
             'request' => {
                            'serialize' => 'std',
                            'path' => '/_search/scroll',
                            'ignore' => [],
                            'mime_type' => 'application/json',
                            'body' => 'c2Nhbjs1OzQ5MjAwNTM6bHExbENzRDVReEc0OV9UMUgzd3Vkdzs1MDUxNDg1OnJrQ3lsUkRKVHRxRWRWeURoOTB4WVE7NDkyMDA1OTpscTFsQ3NENVF4RzQ5X1QxSDN3dWR3OzUwNTE0OTY6cmtDeWxSREpUdHFFZFZ5RGg5MHhZUTs1MDUxNTAwOnJrQ3lsUkRKVHRxRWRWeURoOTB4WVE7MTt0b3RhbF9oaXRzOjUyMTU7',
                            'qs' => {
                                      'scroll' => '1m'
                                    },
                            'method' => 'GET'
                          },
             'status_code' => 404
           },
 'type' => 'Missing'
}, 'Search::Elasticsearch::Error::Missing' );

The code I'm using is the next one (simplified) :

# Retrieve scroll 
my $scroll = $self->getScrollBySignature($item);

# Retrieve all affected documents ids 
while (my @docs = $scroll->next(500)) {
    # Do stuff with @docs
}

The function getScrollBySignature have the next code in order to call to elasticSearch

my $scroll = $self->{ELASTIC}->scroll_helper(
    index              => $self->{INDEXES},
    search_type        => 'scan',
    ignore_unavailable => 1,
    body               => {
        size  => $self->{PAGINATION},
        query => {
            filtered => {
                filter => {
                    bool => {
                        must => [{term => {signature_id => $item->{profileId}}}, {terms => {channel_type_id => $type}}]
                    }
                }
            }
        }
    }
);

As you can see, I'm doing the scroll without passing scroll parameter then as documentation says, the time that scroll is alive is 1 min.

The elasticSearch is a cluster of 3 servers, and the query that ends with that error retrieves a bit more than 5000 docs.

My first solution was to update the life time for scroll to 5 minutes and the error didn't appear.

The question is, as I understand every time I'm calling $scroll->next() the life time off scroll affected is upgraded 1m more, then how is possible to receive those context related errors?

I'm doing something in a bad manner?

Thank you all.

like image 607
jordivador Avatar asked Mar 23 '16 13:03

jordivador


1 Answers

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 ...

like image 146
CatOsMandros Avatar answered Oct 10 '22 08:10

CatOsMandros