title: Many to many relationships in elasticsearch
body: <p>I know that in elasticsearch, we can have <a href="http://www.elasticsearch.org/guide/reference/mapping/parent-field.html">child/parent relationships</a> between documents.</p>
  
  <p>And then, when indexing, I can pass the parent id so that the child and parent documents are linked:</p>
  
  <pre><code>$ curl -XPUT localhost:9200/blogs/blog_tag/1122?parent=1111 -d '{    "tag" : "something"}'
  </code></pre>
  
  <p>Is there anyway to model a many to many relationship in elasticsearch?</p>
  
  <p>Data is resides in a MySQL database with the following schema:</p>
  
  <pre><code>account
  ========
  id
  name
  some_property
  
  group
  ========
  id
  name
  description
  
  account_group
  =============
  account_id
  group_id
  primary_group //This is 1 or 0 depending on whether the group is the primary group for that account.
  </code></pre>
  
  <p>This is currently my mapping for <code>account</code> (please excuse the array notation, I am using <a href="https://github.com/ruflin/Elastica/">Elastica</a> in PHP to talk to my elasticsearch server):</p>
  
  <pre><code>**Mapping for account**
  
  'name' =&gt; array(
      'type' =&gt; 'string'),
  
  'some_property' =&gt; array(
      'type' =&gt; 'string'),
  
  'groups' =&gt; array(
     'properties' =&gt; array(
      'id'      =&gt; array('type' =&gt; 'integer'),
      'primary' =&gt; array('type' =&gt; 'boolean')
      )
  ),
  
  **Mapping for group**
  
  'name' =&gt; array(
          'type' =&gt; 'string'),
  
  'description'=&gt; array(
          'type' =&gt; 'string')
  </code></pre>
  
  <p>The problem with this approach is that if a group is deleted from the index, I will need to go through each account and delete the group id from each account. This seems to be a bit inefficient to me. I also presume that this would not be an issue when using elasticsearch's child/parent relationships.</p>
  
  <p>Is there anyway to model many-to-many relationships in elasticsearch?</p>