Returning a simple projection of fields

I am new to ElasticSearch.

How do I simply get the equivalent to this SQL statement as a CSV formatted file:
SELECT field1, field2, COUNT(field3)
FROM MyTable
GROUP BY field1, field2

You should have a look at aggregations and do something like a termsAgg on field1 add an inner termsAgg on field2.

That should give you something close to your needs.