title: Elastic search sub queries
body: <p>Still trying to get my head around searching joined tables in elastic search.  We have mongodb and its connecting to elastic search through the mongo connector.  </p>
  
  <p>I have two related collections in mongodb; people and images. There will be 8 million people and 20 million images.  Generally people have up to 20 images.  As follows:</p>
  
  <pre><code>people: [ 
    {
      id: ‘123456abc’,
      name: ‘john’,
      town: ‘San Diego’,
      ssn4: '1234' 
    }, 
    {
      id: ‘919645xyz’,
      name: ‘pete’,
      town: ‘Oxford’,
      ssn4: '1234' 
    }
  ]
  
  images: [ 
    {
      id: ‘901’,
      contentType: ‘image/tiff’
      documentType: ‘signature’,
      peopleId: ‘123456abc’ 
    }, 
    {
      id: ‘123’,
      contentType: ‘image/tiff’
      documentType: ‘signature’,
      peopleId: ‘123456abc’ 
    },
    {
      id: ‘456’,
      contentType: ‘image/tiff’
      documentType: ‘mail’,
      peopleId: ‘123456abc’ 
    }
  ]
  </code></pre>
  
  <p>I want to be able to perform a DSL query that returns the images where the documentType = 'signature' and for people living in the town 'San Diego' and have an ssn4 of '1234' (or for a bonus, people who's town contains 'San').</p>