How to get all rows of an sql query?

Hi

Need some help to understand how to read all rows from a query like below:

POST _plugins/_sql
{
“query”: “”" select distinct text_field,field2 from index where text_field like ‘%xyz%’ “”"
}

Index has about 200M documents and result size can be few 1000s to millions.
I need to save the results as a csv file

Hi @abhineet1313,

POST _plugins/_sql results are in JSON format by default. To get the result as CSV you can set the format option How to get all rows of an sql query?.

So the solution would be POST /_plugins/_sql?format=csv