# Elasticsearch node js search\_after

**URL:** <https://discuss.elastic.co/t/elasticsearch-node-js-search-after/268880>\
**Category:** Elasticsearch\
**Tags:** language-clients\
**Created:** [March 31, 2021, 8:53am UTC](https://discuss.elastic.co/t/elasticsearch-node-js-search-after/268880 "2021-03-31T08:53:32Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![111452](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/111452/32/79499_2.png) [@111452](https://discuss.elastic.co/u/111452)\
**Post date:** [March 31, 2021, 8:53am UTC](https://discuss.elastic.co/t/elasticsearch-node-js-search-after/268880/1 "2021-03-31T08:53:32Z")

</div>

Hello everyone! Does anyone know how to properly use search\_after in the elastic query in node js?  
I've tried like :

```auto
'''const body = { "query": { "geo_shape": { "geometry": { "relation": "within", "shape": { "type": "polygon", "coordinates": [$polygon] } } } }, "pit": { "id": $newPIT, "keep_alive": "1m" },
              "sort": [
                {"@timestamp": "asc"}
              ],
              "search_after": $searchAfter
            };
            return client.search({
              size:10000,
              body: body,
            }

```

and

```auto
const body = { "query": { "geo_shape": { "geometry": { "relation": "within", "shape": { "type": "polygon", "coordinates": [$polygon] } } } }, "pit": { "id": $newPIT, "keep_alive": "1m" },
              "sort": [
                {"@timestamp": "asc"}
              ],
            };
         body.search_after = $searchAfter;
            console.log(body)
            return client.search({
              size:10000,
              body: body,
            }

```

$searchAfter variable is taken from the first query after which I would paginate. The value of this variable is something like [9223372036854776000, 32291].  
I am getting search\_phase\_execution\_exception.  
In Kibana query like this works for me, so the problem is the usage of search\_after in node js.

---

<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 28, 2021, 8:54am UTC](https://discuss.elastic.co/t/elasticsearch-node-js-search-after/268880/2 "2021-04-28T08:54:12Z")

</div>

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