How to get output in CSV format in Elastic Node Sql POST method

Can someone help to format the output in CSV for this Node JS code. I am using Elastic 7.10.2. I have tried change the path like /_sql?format=csv its not working. But the same path in Kibana Dev Terminal, I am able to get the csv output. Thanks in advance...

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

From the documentation I see that the format should be passed together with the query body and not in the URL:

Dear Matriv, Thanks for your reply... Can you please elaborate how to pass the format in the query body. And can you please share the documentation's link.

I've provided the url above, e.g.:

  format: "csv",
  body: {
    query: "....."

Thanks a lot Matriv :+1:

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