title: Funnel query with Elasticsearch
body: <p>I'm trying to analyze a funnel using event data in Elasticsearch and have difficulties finding an efficient query to extract that data.</p>
  <p>For example, in Elasticsearch I have:</p>
  <pre><code>timestamp          action        user id
  ---------          ------        -------
  2015-05-05 12:00   homepage      1
  2015-05-05 12:01   product page  1
  2015-05-05 12:02   homepage      2
  2015-05-05 12:03   checkout      1
  </code></pre>
  <p>I would like to extract the funnel statistics. For example:</p>
  <pre><code>homepage_count  product_page_count  checkout_count
  --------------  ------------------  --------------
  2             1                  1
  </code></pre>
  <p>Where homepage_count represent the distinct number of users who visited the homepage, product_page_count represents the distinct numbers of users who visited the homepage after visiting the homepage, and checkout_count represents the number of users who checked out after visiting the homepage and the product page.</p>
  <p>What would be the best query to achieve that with Elasticsearch?</p>