title: How to filter last 5 minutes, date histogram using Elastic search?
body: <p>using Elasticsearch 1.1.1</p>
  
  <p>I'm trying to build a query of "page" views per second for the last 5 minutes for all accounts (so match all).</p>
  
  <p>The mapping is...</p>
  
  <pre><code>"xxx-20140526": {
      "mappings": {
        "xxx": {
          "properties": {
            "accountId": {
              "type": "long"
            },
            "hitTime": {
              "type": "date",
              "format": "dateOptionalTime"
            },
          }
        }
      }
    }
  </code></pre>
  
  <p>The query...</p>
  
  <pre><code>POST /xxx-20140526/xxx/_search
  {
    "filter": {
      "range": {
        "timeHit": {
          "gte": "2014-05-26T13:40", //Date generated dynamically now - 5mins
          "lt": "2014-05-26T13:45" //Date generated dynamically now
        }
      }
    },
    "aggs": {
      "views_per_sec": {
        "date_histogram": {
          "field": "timeHit",
          "interval": "second"
        }
      }
    }
  }
  </code></pre>
  
  <p>But the aggregation also returns values from previous times...</p>
  
  <pre><code>"aggregations": {
      "trx_per_sec": {
          "buckets": [
          {
              "key_as_string": "2014-05-26T13:36:46.000Z",
              "key": 1401111166000,
              "doc_count": 72
          },
          ... Other dates in the 30 mins range here...
          {
             "key_as_string": "2014-05-26T13:42:47.000Z",
             "key": 1401111167000,
             "doc_count": 5013
          }
       }
  }
  </code></pre>
  
  <p>1- Do aggregations consider the filter?
  2- Is it the right way to filter for the last 5 minutes or should I look at date aggregations?</p>
  
  <p>I also tried...</p>
  
  <pre><code>{
    "aggs": {
      "range": {
        "date_range": {
          "field": "timeHit",
          "format": "yyyy-MM-dd HH:mm:ss",
          "ranges": [
            {
              "from": "now-5m"
            }
          ]
        }
      }
    }
  }
  </code></pre>
  
  <p>But this doesn't seem to return the right amount of docs.</p>