title: Elasticsearch- sum specific field in specific datetime range?
body: <p>I have a requirement of find sum one fields in a single query. I have managed to sum specific field in specific datetime range .
  I try to use aggregation query to get the field total in specific datetime range,but get total value is 0 </p>
  
  <p>My document json look like the following way :</p>
  
  <pre><code>{
    "_index": "flow-2018.02.01",
    "_type": "doc",
    "_source": {
      "@timestamp": "2018-02-01T01:02:40.701Z",
      "dest": {
        "ip": "120.119.37.237",
        "mac": "d4:6d:50:21:f8:44",
        "port": 3280
      },
      "final": true,
      "flow_id": "EQQA////DP//////FP8BAAFw5CIXZxTUbVAh+ERn/7FMeHcl7S6z0Aw",
      "last_time": "2018-02-01T01:01:48.349Z",
      "source": {
        "ip": "100.255.177.76",
        "mac": "70:e4:30:15:67:14",
        "port": 45870,
         "stats": {
           "bytes_total": 60,
           "packets_total": 1
        }
      },
      "start_time": "2018-02-01T01:01:48.349Z",
      "transport": "tcp",
      "type": "flow"
    },
     "fields": {
      "start_time": [
        1517446908349
      ],
      "@timestamp": [
        1517446960701
      ],
      "last_time": [
        1517446908349
      ]
    },
    "sort": [
      1517446960701
    ]
  }
  </code></pre>
  
  <p>My search query :</p>
  
  <pre><code>    {
     "size":0,
     "query":{
        "bool":{
           "must":[
               {
                 "range":{
                    "_source.@timestamp":{
                       "gte": "2018-02-01T01:00:00.000Z",
                       "lte": "2018-02-01T01:05:00.000Z"
                    }
                 }
              }
           ]
        }
     },
     "aggs":{
        "total":{
           "sum":{
              "field":"stats.packets_total "
           }
        }
     }
  }
  </code></pre>
  
  <p>Please help me to solve this issue. Thank you</p>