title: ElasticSearch: filter out results from an array
body: <p>I have an array that's of form:</p>
  
  <pre><code>[ { _index: 'people',
      _type: 'items',
      _id: '5450c69d9d3545a816df39d4',
      _score: null,
      _source:
       { _id: '5450c69d9d3545a816df39d4',
         number: '2062',
         bids: [Object] },
    { _index: 'people',
      _type: 'items',
      _id: '5450c69d9d3545a816df396d',
      _score: null,
      _source:
       { _id: '5450c69d9d3545a816df396d',
         number: '2195',
         bids: [Object] }
   ]
  </code></pre>
  
  <p><strong>Detailed item-</strong></p>
  
  <pre><code>{ _id: '5450c69d9d3545a816df391c',
    number: '2004',
    bids:
     [ { collector: '5450c69a9d3545a816df311d',
         state: 'losing',
         createdAt: '2014-10-30T09:33:36.905Z',
         amount: 10,
         _id: '545205f01fc10e3816cb2073' },
       { collector: '5450c69a9d3545a816df311c',
         amount: 20,
         state: 'winning',
         createdAt: '2014-10-30T09:29:38.561Z',
         _id: '545205f01fc10e3816cb2074' } ]
  }
  </code></pre>
  
  <p>I want to apply a filter such that I can filter out the winning and losing bids. I want a query that returns the result of such type,ie, the collector who is winning on this item.</p>
  
  <pre><code>{ collector: '5450c69a9d3545a816df311c',
     amount: 20,
     state: 'winning',
     createdAt: '2014-10-30T09:29:38.561Z',
     _id: '545205f01fc10e3816cb2074' } ]
  </code></pre>
  
  <p><strong>The mapping is :</strong></p>
  
  <pre><code>{
    "bids": {
      "properties": {
        "_id": {
          "type": "string"
        },
        "amount": {
          "type": "long"
        },
        "collector": {
          "type": "string"
        },
        "createdAt": {
          "type": "date",
          "format": "dateOptionalTime"
        },
        "state": {
          "type": "string"
        }
      }
    }
  }
  </code></pre>
  
  <p>The query should be like <code>collector=&lt;id&gt; AND bids.state="winning/losing"</code></p>
  
  <p>What would be the actual ElasticSearch query?</p>