title: How to get elasticsearch all records into csv file using query command
body: <p>I'm using elastic search for data and jqxgrid for the display the data. so my requirement is user can also download the grid data using above download button. and it is working fine using jqxgrid functionality. but it only fetch the data from the current records not all because pagination is done by server side so it will export the current page data. My requirement is user can click on download button and the all data exported to csv file.</p>
  
  <p><a href="https://www.jqwidgets.com/jquery-widgets-demo/demos/jqxgrid/dataexport.htm" rel="nofollow noreferrer">jqxgrid export functionality is not worked with all pages.</a></p>
  
  <p>I have checked many solution like .
  1. logstash csv export plugin.
  2. Is it possible with query that we make a pull request and store the output to csv file.</p>
  
  <p>By default elasticsearch query give the data into json format if i fetch all data and convert into csv is not optimal solution.</p>
  
  <pre><code>input {
   elasticsearch {
      hosts =&gt; "localhost:9200"
      index =&gt; "magic"
      query =&gt; '
      {"query":{"bool":{"must":[{"term":{"product_id":"424509"}}],"must_not":[],"should":[]}},"from":0,"size":10,"sort":[],"aggs":{}}
      }
  }'
    }
  }
  output {
    csv {
    fields =&gt; ["product_id"]
    path =&gt; "/tmp/csv-export55513.csv"
    }
  }
  
  
  curl -o /path/to/file.csv -XGET "localhost:9200/{index}/{type}/_data?format=csv&amp;source={source}"
  </code></pre>
  
  <p>So is there any straight way to download all data. </p>