title: How can I count the number of documents where a field is within a certain range?
body: <p>I am trying to build an elasticsearch query that counts the number of documents where a certain field is within a certain range. This aggregation is also contained inside of a date histogram aggregation, but I don't think that matters for the purpose of this question.</p>
  
  <p>Example Data:</p>
  
  <pre><code>ID: Score
  01: 4
  02: 5
  03: 10    
  04: 9
  </code></pre>
  
  <p>I would like to count the number of documents where 'Score' is >= 9. I have tried scripts and filters within this aggregation, but I can't get it to work.</p>
  
  <p>This aggregation counts all documents, not just the ones that match the script.</p>
  
  <pre><code>"aggs": {
      "report_days": {
          "date_histogram": {
              "field": "Date",
              "interval": "day"
          },
          "aggs": {
              "value_count": {
                  "field": "Score",
                  "script": "_value &gt;=9"
              }
          }
      }
  }
  </code></pre>
  
  <p>This following aggregation gives me a parse failure, saying <code>Parse Failure [Expected [START_OBJECT] under [field], but got a [VALUE_STRING] in [value_count]]</code>:</p>
  
  <pre><code>"aggs": {
      "report_days": {
          "date_histogram": {
              "field": "Date",
              "interval": "day"
          },
          "aggs": {
              "value_count": {
                  "field": "Score",
                  "filter": {
                      "range": {
                          "Score": {
                              "gte": 9
                          }
                      }
                  }
              }
          }
      }
  }
  </code></pre>
  
  <p>Thanks for any suggestions!</p>