title: Haystack & ElasticSearch: Searching Related Fields; Use nested Type?
body: <p>I am using django-haystack on elastic search.  My indexed documents each have a number of people's names and for each person, their role associated with the document.  For example:</p>
  
  <pre><code>Doc1:
     name='Bob',  role='Author'
     name='Jill', role='Editor'
     name='Joe',  role='Publisher'
  
  Doc2:
     name='Jill',  role='Author'
     name='Phill', role='Editor'
     name='Janet', role='Contributor'
  </code></pre>
  
  <p>How would I setup my index to allow me to do the search: "find all documents where <code>Jill</code> is an <code>Author</code>"?  In the above example, I would want it to return only <code>Doc2</code> and <strong>not</strong> <code>Doc1</code>.</p>
  
  <p>There are hundreds of different types of roles a person can have, so it isn't realistic to have an index field for each type.  I thought about having a single index field joining the two together (e.g., <code>name_role=indexes.CharField(...)</code>), where each entry has a delimiter that I would parse (e.g., <code>"Jill#Author"</code>). But that seems ugly.</p>
  
  <p>Are there any better ways to do this?  I feel like <a href="http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/mapping-nested-type.html" rel="nofollow">ElasticSearch's <code>nested</code> type</a> may be able to help, but I'm not sure.</p>
  
  <p>Even though I'm using django-haystack, if there is an elasticsearch specific answer, I'd be happy to hear it.</p>