# Problems with Scroll and Slice

**URL:** <https://discuss.elastic.co/t/problems-with-scroll-and-slice/324271>\
**Category:** Elasticsearch\
**Created:** [January 30, 2023, 9:17pm UTC](https://discuss.elastic.co/t/problems-with-scroll-and-slice/324271 "2023-01-30T21:17:29Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Olli1](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/olli1/32/116565_2.png) [@Olli1](https://discuss.elastic.co/u/Olli1)\
**Post date:** [January 30, 2023, 9:17pm UTC](https://discuss.elastic.co/t/problems-with-scroll-and-slice/324271/1 "2023-01-30T21:17:29Z")

</div>

Hello Com,  
i have a problem with my Code. When i want to Scroll and Slice about 100.000 data, i get the following Error:

```auto
# Request:
{"scroll":"2m","scroll_id":"FGluY2x1ZGVfY29udGV4dF91dWlkDnF1ZXJ5VGhlbkZldGNoAhZvNUctQkZ5TVRUS0NNaEFtNGY4QWFBAAAAAAAKZuIWd3BLUERNT2FRSC0xa0Ztd09jVl9jdxZvNUctQkZ5TVRUS0NNaEFtNGY4QWFBAAAAAAAKZuMWd3BLUERNT2FRSC0xa0Ztd09jVl9jdw=="}
# Response:
{"error":{"root_cause":[{"type":"search_context_missing_exception","reason":"No search context found for id [681698]"},{"type":"search_context_missing_exception","reason":"No search context found for id [681699]"}],"type":"search_phase_execution_exception","reason":"all shards failed","phase":"query","grouped":true,"failed_shards":[{"shard":-1,"index":null,"reason":{"type":"search_context_missing_exception","reason":"No search context found for id [681698]"}},{"shard":-1,"index":null,"reason":{"type":"search_context_missing_exception","reason":"No search context found for id [681699]"}}],"caused_by":{"type":"search_context_missing_exception","reason":"No search context found for id [681699]"}},"status":404}
# Exception:
Elasticsearch.Net.ElasticsearchClientException: scrolling search on /_search/scroll with slice 2 was not valid on scroll iteration 1

```

```auto
int numberOfSlices = 9;
               long totalHits = 0;

               logDuration();

               Log.GetLog()
                   .Verbose($"MaxDegreeOfParallelism: {numberOfSlices}");
               var scrollAllMyOberversable = elasticClient.ScrollAll<IDictionary<string, object>>("2m",
                   numberOfSlices, sc => sc
                       .MaxDegreeOfParallelism(numberOfSlices)
                       .Search(s => s
                           .Query(q => searchRequest.Query)
                           .Size(searchRequest.Size)));
               var waitHandle = new ManualResetEvent(false);
               
               ExceptionDispatchInfo info = null;
               var scrollAllObserv = new ScrollAllObserver<IDictionary<string, object>>(
                   onNext: response =>
                   {
                       result.AddRange(response.SearchResponse.Documents);
                       totalHits += response.SearchResponse.Documents.Count;

                   },

                   onError: e =>
                   {
                       info = ExceptionDispatchInfo.Capture(e);
                       waitHandle.Set();
                   },
                   onCompleted: () =>
                   {
                       waitHandle.Set();
                       logDuration();
                   });
               scrollAllMyOberversable.Subscribe(scrollAllObserv);
               waitHandle.WaitOne();
               info?.Throw();

               logDuration();

               Log.GetLog()
                   .Verbose(
                       $"Result.Search: {durations.Sum(s => s.Value)}ms, {JsonConvert.SerializeObject(durations, Formatting.Indented)}");
               stopWatch.Restart();

```

Any Idea what i did wrong?

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [February 27, 2023, 9:17pm UTC](https://discuss.elastic.co/t/problems-with-scroll-and-slice/324271/2 "2023-02-27T21:17:34Z")

</div>

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.
