# ElasticSearch.NET - Overflow exception when using scrollAPI or search\_after

**URL:** <https://discuss.elastic.co/t/elasticsearch-net-overflow-exception-when-using-scrollapi-or-search-after/224449>\
**Category:** Elasticsearch\
**Created:** [March 20, 2020, 4:21pm UTC](https://discuss.elastic.co/t/elasticsearch-net-overflow-exception-when-using-scrollapi-or-search-after/224449 "2020-03-20T16:21:15Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![salunkerahul](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/salunkerahul/32/47522_2.png) [@salunkerahul](https://discuss.elastic.co/u/salunkerahul)\
**Post date:** [March 20, 2020, 4:21pm UTC](https://discuss.elastic.co/t/elasticsearch-net-overflow-exception-when-using-scrollapi-or-search-after/224449/1 "2020-03-20T16:21:15Z")

</div>

I'm attempting read all data from a particular index using the Scroll API(ElasticSearch.NET-7.4.2), but I end up with the following exception

```auto

    # FailureReason: Unrecoverable/Unexpected BadResponse while attempting POST on http://localhost:9200/_search/scroll?pretty=true&error_trace=true
     - [1] BadResponse: Node: http://localhost:9200/ Exception: OverflowException Took: 00:00:00.0490000

```

The code is as follows:

```auto

    [ElasticsearchType]
    public class SPEXEC
    {
        [Text(Name="event_type")]
        //[JsonProperty("event_type")]
        public string EventType{ get; set; }

        [Text(Name="client_app_name")]
        //[JsonProperty("client_app_name")]
        public string ClientAppName{ get; set; }
    }
    var settings = new ConnectionSettings(new Uri("http://localhost:9200"))
        .DefaultIndex("filebeat-7.5.2")
        .EnableDebugMode()
        .PrettyJson()
        .RequestTimeout(TimeSpan.FromMinutes(2));
    var searchResponse = client.Search<SPExec>(s => s.Index("filebeat-7.5.2-2020.03.19-000002").MatchAll().Scroll("3m").Size(1000));
    while (searchResponse.Documents.Any())
    {
        var resp = new ISearchResponse<SPExec>
        {
            Results = searchResponse.Documents,
            ElapsedMilliseconds = (int)searchResponse.Took,
        };
        searchResponse = client.Scroll<SPExec>("1m", searchResponse.ScrollId); // Overflow exception
    }
    client.ClearScroll(c => c.ScrollId(searchResponse.ScrollId));

```

The aim of using Scroll API is to read data from Elastic to generate reports. I don't encounter any errors when using scrolling within the Dev Console.

```auto
    POST filebeat-7.5.2-2020.03.19-000002/_search?scroll=1m
    {
      "query": {
        "match_all": {}
      }
      , "size": 1000
    }

    POST /_search/scroll 
    {
        "scroll" : "1m", 
        "scroll_id" : "DXF1ZXJ5QW5kRmV0Y2gBAAAAAAAAX3sWOGZwN1NKUVVUNlc1dEFxbDRSZmxtQQ=="
    }

    POST /_search/scroll 
    {
        "scroll" : "1m", 
        "scroll_id" : "DXF1ZXJ5QW5kRmV0Y2gBAAAAAAAAX3sWOGZwN1NKUVVUNlc1dEFxbDRSZmxtQQ=="
    }

```

If there something obvious that I've missed out when using Scroll API, do point me in the right direction. I've also run the application using ElasticSearch-7.6.1 and I end up with the same exception.

I also attempted to use the search\_after, which as the documentation suggests is for real-time user requests which also failed with an Overflow exception.

```auto
var searchResponse = client.Search<SPEXEC>(s => s.Index(index)
        .MatchAll()
        .Size(1000)
        .Sort(ss => ss
        .Ascending(p => p.Timestamp)
        .Descending(p => p.ElasticID)));
while (true)
{
    if (searchResponse.Documents.Any())
    {
       hitTotal += searchResponse.Hits.Count;
       var searchAfter = searchResponse.Hits.Last().Sorts.ToArray();
       searchResponse = client.Search<SPEXEC>(s => s.Index(index)
          .MatchAll()
         .Size(1000)
         .Sort(ss => ss
                .Ascending(p => p.Timestamp)
                .Descending(p => p.ElasticID))
         .SearchAfter(searchAfter));
  }
  else
 {
    System.Threading.Thread.Sleep(5 * 60 * 1000);
 }
   }

```

---

<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:** [April 17, 2020, 4:21pm UTC](https://discuss.elastic.co/t/elasticsearch-net-overflow-exception-when-using-scrollapi-or-search-after/224449/2 "2020-04-17T16:21:17Z")

</div>

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