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

**URL:** <https://discuss.elastic.co/t/how-to-get-output-in-csv-format-in-elastic-node-sql-post-method/275330>\
**Category:** Elasticsearch\
**Tags:** elastic-stack-sql\
**Created:** [June 8, 2021, 5:25pm UTC](https://discuss.elastic.co/t/how-to-get-output-in-csv-format-in-elastic-node-sql-post-method/275330 "2021-06-08T17:25:10Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Resington\_R](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/resington_r/32/85143_2.png) [@Resington\_R](https://discuss.elastic.co/u/Resington_R)\
**Post date:** [June 8, 2021, 5:25pm UTC](https://discuss.elastic.co/t/how-to-get-output-in-csv-format-in-elastic-node-sql-post-method/275330/1 "2021-06-08T17:25:10Z")

</div>

Hi...  
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...

```auto
async function mysqlfunc(req, res) {  
    client.transport.request({
        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);
            res.send(response.rows);
        }
    });
}

```

---

<div class="post-metadata">

**Author:** ![matriv](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/matriv/32/43656_2.png) [@matriv](https://discuss.elastic.co/u/matriv)\
**Post date:** [June 9, 2021, 7:33am UTC](https://discuss.elastic.co/t/how-to-get-output-in-csv-format-in-elastic-node-sql-post-method/275330/2 "2021-06-09T07:33:07Z")

</div>

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

> **[API Reference | Elasticsearch Node.js client \[7.x\] | Elastic](https://www.elastic.co/guide/en/elasticsearch/client/javascript-api/current/api-reference.html#_sql_query)**

---

<div class="post-metadata">

**Author:** ![Resington\_R](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/resington_r/32/85143_2.png) [@Resington\_R](https://discuss.elastic.co/u/Resington_R)\
**Post date:** [June 9, 2021, 9:25am UTC](https://discuss.elastic.co/t/how-to-get-output-in-csv-format-in-elastic-node-sql-post-method/275330/3 "2021-06-09T09:25:10Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![matriv](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/matriv/32/43656_2.png) [@matriv](https://discuss.elastic.co/u/matriv)\
**Post date:** [June 9, 2021, 1:19pm UTC](https://discuss.elastic.co/t/how-to-get-output-in-csv-format-in-elastic-node-sql-post-method/275330/4 "2021-06-09T13:19:58Z")

</div>

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

```auto
client.sql.query({
  format: "csv",
  body: {
    query: "....."
  }
})

```

---

<div class="post-metadata">

**Author:** ![Resington\_R](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/resington_r/32/85143_2.png) [@Resington\_R](https://discuss.elastic.co/u/Resington_R)\
**Post date:** [June 9, 2021, 7:42pm UTC](https://discuss.elastic.co/t/how-to-get-output-in-csv-format-in-elastic-node-sql-post-method/275330/5 "2021-06-09T19:42:26Z")

</div>

Thanks a lot Matriv 👍

---

<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:** [July 7, 2021, 7:43pm UTC](https://discuss.elastic.co/t/how-to-get-output-in-csv-format-in-elastic-node-sql-post-method/275330/6 "2021-07-07T19:43:19Z")

</div>

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