title: Difficulty combining bool and range query, elastic search
body: <p>I'm having a bit of trouble understanding the various ways to nest queries in elastic search. Here is an example of what my indexed data looks like..</p>
  
  <pre><code>{
      "Underlying" : "Eurodollar",
      "Expiration" : "20160315"
  },
  {
      "Underlying" : "Eurodollar",
      "Expiration" : "20160415"
  },
  {
      "Underlying" : "Eurodollar",
      "Expiration" : "20160515"
  }
  </code></pre>
  
  <p>So, I was able to run a query like this</p>
  
  <pre><code>{
      "query" : {
          "range" : {
              "Expiration" : {
                  "gte" : "20160315",
                  "lte" : "20160515"
              }
          }
      }
  }
  </code></pre>
  
  <p>And as expected, I get all entries. HOWEVER, suppose I ALSO have indexed entries like this.</p>
  
  <pre><code>{
     "Underlying" : "Something else",
     "Expiration" : "20160415"
  }
  </code></pre>
  
  <p>I don't want the "Something else" results to come back, so I now attempt to do something like this.</p>
  
  <pre><code>{
      "query" : {
          "bool" : {
              "must" : [
                  {
                      "term" : {
                          "Underlying" : {
                              "value" : "eurodollar"
                          }
                      }
                  }
              ]
          },
          "range" : {
              "Expiration" : {
                  "gte" : "20160315",
                  "lte" : "20160515"
              }
          }
      }
  }
  </code></pre>
  
  <p>But I am getting an error</p>
  
  <pre><code>RequestError(400, u'SearchPhaseExecutionException[Failed to execute phase [query], all shards failed; shardFailures {[cCrh939sR7yHdKgawRi6Sw][test-index][0]: SearchParseException[[test-index][0]: query[Expiration:[20160215 TO 20160415]],from[-1],size[-1]: Parse Failure [Failed to parse source [{"query": {"range": {"Expiration": {"gte": "20160215", "lte": "20160415"}}, "bool": {"must": [{"term": {"Underlying": {"value": "eurodollar"}}}]}}}]]]; nested: ElasticsearchParseException[Expected field name but got START_OBJECT "bool"]; }{[cCrh939sR7yHdKgawRi6Sw][test-index][1]: SearchParseException[[test-index][1]: query[Expiration:[20160215 TO 20160415]],from[-1],size[-1]: Parse Failure [Failed to parse source [{"query": {"range": {"Expiration": {"gte": "20160215", "lte": "20160415"}}, "bool": {"must": [{"term": {"Underlying": {"value": "eurodollar"}}}]}}}]]]; nested: ElasticsearchParseException[Expected field name but got START_OBJECT "bool"]; }]', {u'status': 400, u'error': u'SearchPhaseExecutionException[Failed to execute phase [query], all shards failed; shardFailures {[cCrh939sR7yHdKgawRi6Sw][test-index][0]: SearchParseException[[test-index][0]: query[Expiration:[20160215 TO 20160415]],from[-1],size[-1]: Parse Failure [Failed to parse source [{"query": {"range": {"Expiration": {"gte": "20160215", "lte": "20160415"}}, "bool": {"must": [{"term": {"Underlying": {"value": "eurodollar"}}}]}}}]]]; nested: ElasticsearchParseException[Expected field name but got START_OBJECT "bool"]; }{[cCrh939sR7yHdKgawRi6Sw][test-index][1]: SearchParseException[[test-index][1]: query[Expiration:[20160215 TO 20160415]],from[-1],size[-1]: Parse Failure [Failed to parse source [{"query": {"range": {"Expiration": {"gte": "20160215", "lte": "20160415"}}, "bool": {"must": [{"term": {"Underlying": {"value": "eurodollar"}}}]}}}]]]; nested: ElasticsearchParseException[Expected field name but got START_OBJECT "bool"]; }]'})
  </code></pre>
  
  <p>The most relevant text of the error seems to be this</p>
  
  <pre><code> Expected field name but got START_OBJECT "bool"
  </code></pre>
  
  <p>I know my bool/term query is working, because I ran just this</p>
  
  <pre><code>{
      "query" : {
          "bool" : {
              "must" : [
                  {
                      "term" : {
                          "Underlying" : {
                              "value" : "eurodollar"
                          }
                      }
                  }
              ]
          }
      }
  }
  </code></pre>
  
  <p>And I got back the expected results.</p>
  
  <p>I think this illustrates my situation well enough. How do I properly combine these queries, given that my guess as to how they should be combined is incorrect.</p>