title: What is the best way to index aggregate data on ElasticSearch
body: <p>I have users and my users have events. Each event as a type and date on each the event happened.</p>
  
  <p>For example</p>
  
  <pre><code>{
    id: 1,
    name: john,
    events: [{
      type: 'logged_in'
      date: "01/01/2016
    },{
      type: 'logged_in'
      date: "02/01/2016
    }{
      type: 'added_email'
      date: "02/05/2016
    }]
  }
  </code></pre>
  
  <p>Now the issue is that I would like to able to query users that have done a specific event N times for a specific time frame</p>
  
  <p>For example: Which users logged in more than twice between Jan 1 16 and Jan 20 17</p>
  
  <p>I know I can use aggregates but the query gets complex and performance drops on million of events. </p>
  
  <p>I was wondering if there is a better way to index/query this data?</p>