Problems with from/size pagination on Node.js API

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!

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

Hey, I edited my original post.

UPDATE: I solved it!

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

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