title: Join documents in elasticsearch
body: <p>I have these product documents:</p>
  
  <pre><code>curl -XPOST -H 'Content-Type: application/json' "http://localhost:9200/test/_bulk?pretty" -d'
  {"index":{"_index":"test","_type":"product"}}
  {"id":"1", "price": "260" }
  {"index":{"_index":"test","_type":"product"}}
  {"id":"2", "price": "420" }
  {"index":{"_index":"test","_type":"product"}}
  {"id":"3", "price": "250" }
  </code></pre>
  
  <p>And these discount documents:</p>
  
  <pre><code>curl -XPOST -H 'Content-Type: application/json' "http://localhost:9200/test/_bulk?pretty" -d'
  {"index":{"_index":"test","_type":"discount"}}
  {"product_id":"1", "group_id": 12, "percent": "50" }
  {"index":{"_index":"test","_type":"discount"}}
  {"product_id":"1", "group_id": 15, "percent": "20" }
  {"index":{"_index":"test","_type":"discount"}}
  {"product_id":"3", "group_id": 12, "percent": "10" }
  </code></pre>
  
  <p>I need to join these two documents via the <code>product_id</code> and <code>group_id</code> key.</p>
  
  <p>In the mysql database would look like this:</p>
  
  <pre><code>SELECT p.id, IF(d.percent &gt; 0, p.price - (d.percent*p.price/100), p.price) price 
  FROM product p
  LEFT JOIN discount d ON p.id=d.product_id AND d.group_id=12
  WHERE IF(d.percent &gt; 0, p.price - (d.percent*p.price/100), p.price) &lt; 210
  </code></pre>
  
  <p>The result of that query will be only one row:</p>
  
  <pre><code>id =&gt; 1
  price =&gt; 130
  </code></pre>
  
  <p>Is it possible to do in elasticsearch?</p>