title: Average and group by query ElasticSearch
body: <p>I have some data in elasticsearch where for same value of time there are different speed values (there are seconds and millisecond fields). I want to group by the seconds and fetch average speed for that second. In short looking out for a es query like :</p>
  
  <pre><code>select average(speed) as speed, sec from index group by sec order by sec asc
  </code></pre>