# Problems with from/size pagination on Node.js API

**URL:** <https://discuss.elastic.co/t/problems-with-from-size-pagination-on-node-js-api/219619>\
**Category:** Elasticsearch\
**Tags:** language-clients\
**Created:** [February 17, 2020, 12:46pm UTC](https://discuss.elastic.co/t/problems-with-from-size-pagination-on-node-js-api/219619 "2020-02-17T12:46:25Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![lleal](https://avatars.discourse-cdn.com/v4/letter/l/b487fb/32.png) [@lleal](https://discuss.elastic.co/u/lleal)\
**Post date:** [February 17, 2020, 12:46pm UTC](https://discuss.elastic.co/t/problems-with-from-size-pagination-on-node-js-api/219619/1 "2020-02-17T12:46:25Z")

</div>

Hi folks,

I am currently running in some weird behavior while running paginated searches using the Node.js API. From my tests it seems that the "from" parameter is not being correctly parsed. No matter the value I configure it will always start from 0-index.

For example, when I run this query on Kibana console It will return 2 hits. If I change the "from" parameter to 0 or 1, I can actually recover each entry at a time.

```
GET my-customers/_search
{
  "query": {
    "bool": {
      "must": {
        "multi_match": {
          "query": "ju",
          "fuzziness": "AUTO",
          "fields": [
            "firstName",
            "lastName",
            "email"
          ]
        }
      },
      "filter": []
    }
  },
  "size": 1,
  "from": 1
}

```

However, when I do the same on my Node application, I always get the first hit no matter the "from" value I setup.

```
queryValue = 'ju';

const query = {
   index: "my-customers",
   from: 1,
   size: 1,
   body: {
     "query": {
       "bool": {
         "must": {
           "multi_match": {
             "query": queryValue,
             "fuzziness": "AUTO",
             "fields": fields
           }
         },
         "filter": []
       }
     }
   },
 }; 

try {
  const result = await es.search(query);
  return success(mapResult(result));
} catch (e) {
    return failure({
      status: false
    });
}

```

And the mapResult function:

```
export const mapResult = (result) => ({
  total: result.hits.total.value,
  items: result.hits.hits.length > 0 && result.hits.hits.map(hit => ({
    id: hit._id,
    ...hit._source,
  })) || [],
});

```

Anyone else encountered such problem?

Thanks!

---

<div class="post-metadata">

**Author:** ![spinscale](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/spinscale/32/25011_2.png) [@spinscale](https://discuss.elastic.co/u/spinscale)\
**Post date:** [February 17, 2020, 1:21pm UTC](https://discuss.elastic.co/t/problems-with-from-size-pagination-on-node-js-api/219619/2 "2020-02-17T13:21:45Z")

</div>

hey, can you share a full code snippet including the client search method call?

---

<div class="post-metadata">

**Author:** ![lleal](https://avatars.discourse-cdn.com/v4/letter/l/b487fb/32.png) [@lleal](https://discuss.elastic.co/u/lleal)\
**Post date:** [February 17, 2020, 2:32pm UTC](https://discuss.elastic.co/t/problems-with-from-size-pagination-on-node-js-api/219619/3 "2020-02-17T14:32:21Z")

</div>

Hey, I edited my original post.

---

<div class="post-metadata">

**Author:** ![lleal](https://avatars.discourse-cdn.com/v4/letter/l/b487fb/32.png) [@lleal](https://discuss.elastic.co/u/lleal)\
**Post date:** [February 18, 2020, 4:37pm UTC](https://discuss.elastic.co/t/problems-with-from-size-pagination-on-node-js-api/219619/4 "2020-02-18T16:37:10Z")

</div>

UPDATE: I solved it!

My wrapper for the ES client was ignoring some parameters, "from" among them. Everything is working now as expected.

---

<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 17, 2020, 4:37pm UTC](https://discuss.elastic.co/t/problems-with-from-size-pagination-on-node-js-api/219619/5 "2020-03-17T16:37:13Z")

</div>

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