title: ElasticSearch count multiple fields grouped by
body: <p>I have documents like</p>
  
  <pre><code>{"domain":"US", "zipcode":"11111", "eventType":"click", "id":"1", "time":100}
  
  {"domain":"US", "zipcode":"22222", "eventType":"sell", "id":"2", "time":200}
  
  {"domain":"US", "zipcode":"22222", "eventType":"click", "id":"3","time":150}
  
  {"domain":"US", "zipcode":"11111", "eventType":"sell", "id":"4","time":350}
  
  {"domain":"US", "zipcode":"33333", "eventType":"sell", "id":"5","time":225}
  
  {"domain":"EU", "zipcode":"44444", "eventType":"click", "id":"5","time":120}
  </code></pre>
  
  <p>I want to filter these documents by eventType=sell and time between 125 and 400, group by domain followed by zipcode and count the documents in each bucket. So my output would be like (first and last docs would be ignored by the filters)</p>
  
  <p>US, 11111,1</p>
  
  <p>US, 22222,1</p>
  
  <p>US, 33333,1</p>
  
  <p>In SQL, this should have been straightforward. But I am not able to get this to work on ElasticSearch. Could someone please help me out here?</p>
  
  <p>How do I write ElasticSearch query to accomplish the above?</p>