How to set the LIMIT with FROM and TO in ES Sql query?

Hi... Can anyone please tell me how to set the Limit with FROM and TO. The below query returns more than 10 thousand records, where I would like to Paginate 50 records in a page. Is there any possibility to set limit with range or is there any other option to do this. Thanks in advance..

async function mysqlfunc(req, res) {  
    client.transport.request({
        method: "POST",
        path: "/_sql",
        body: {
            query: "SELECT field1, filed2 FROM myindex limit 10",
            fetch_size: 50
        }
    }, function(error, response) {
        if (error) {
            console.error('Something does not compute : ' + error);
        } else {           
            console.log("Output : " + response.rows);
            res.send(response.rows);
        }
    });
}

Then you keep the fetch_size as you have and get rid of the LIMIT, so the 1st response apart from the rows will return to you a cursor ID which you can use to scroll through the next pages:

So in the next pages you don't provide a query: anymore in the body but a cursor, and don't forget to clear the cursor once you're done to free up the resources:

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