# Searches using Search\_after timeout after three pages

**URL:** <https://discuss.elastic.co/t/searches-using-search-after-timeout-after-three-pages/169122>\
**Category:** Elasticsearch\
**Created:** [February 20, 2019, 2:20am UTC](https://discuss.elastic.co/t/searches-using-search-after-timeout-after-three-pages/169122 "2019-02-20T02:20:12Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![ishanip](https://avatars.discourse-cdn.com/v4/letter/i/f14d63/32.png) [@ishanip](https://discuss.elastic.co/u/ishanip)\
**Post date:** [February 20, 2019, 2:20am UTC](https://discuss.elastic.co/t/searches-using-search-after-timeout-after-three-pages/169122/1 "2019-02-20T02:20:12Z")

</div>

Hello,

I have about 117 million records in Elasticsearch and I am trying to fetch 2.5 million records using pagination. I tried to use the Scroll API and the Search\_After. Since I want to fetch such huge number of records frequently, I ruled out Scroll API as my best option. I am using elastic search v6.4

Using search\_after, I have been seeing that requests time out consistently after three pages and the time taken for ES search queries is much higher too. What is the ideal way to use search\_after to fetch millions of records? And can these search\_after queries be issued in parallel?  
Here is what my sample query looks like-

```
POST /indexname/_search
{
  "size": 10000,
  "sort": [
    {
      "docid": {
        "order": "asc"
      },
      "date": {
        "order": "asc"
      }
    }
  ],
  "search_after": [
          "02073930-F6E8-47D8-8E72-72F335B79F09",
          1539820800000
        ],
  "query": {
    "bool": {
      "filter": [
        {
          "bool": {
            "must": [
              {
                "term": {
                  "testId": {
                    "value": 1540401
                  }
                }
              },
              {
                "term": {
                  "testCode": {
                    "value": "0bfa81a6-9e1e-437b-9600-bcf22d50781a"
                  }
                }
              }
            ]
          }
        },
        {
          "bool": {
            "must_not": [
              {
                "terms": {
                  "testStatus": [
                    "CANCELLED",
                    "REJECTED"
                  ]
                }
              }
            ]
          }
        }
      ]
    }
  }
}
```

---

<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:** [March 20, 2019, 2:20am UTC](https://discuss.elastic.co/t/searches-using-search-after-timeout-after-three-pages/169122/2 "2019-03-20T02:20:21Z")

</div>

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