title: How to subtract aggregate min from aggreagate max(difference) in ES?
body: <p>How to write an ES query to find the difference between max and min value of a field?</p>
  
  <p>I am a newbee in elastic search,
  In my case I feed lot of events along with session_id and time in to elastic search.
  My event structure is</p>
  
  <pre><code>Event_name string    `json:"Event_name"`
  Client_id  string    `json:"Client_id"`
  App_id     string    `json:"App_id"`
  Session_id string    `json:"Session_id"`
  User_id    string    `json:"User_id"`
  Ip_address string    `json:"Ip_address"`
  Latitude   int64     `json:"Latitude"`
  Longitude  int64     `json:"Longitude"`
  Event_time time.Time `json:"Time"`
  </code></pre>
  
  <p>I want to find the life time of a session_id based the feeded events.
  For that I can retrive the maximum Event_time and minimum Event_time for a particular session_id by the following ES query.</p>
  
  <pre><code>{  
    "size": 0,
    "query": {
       "match": {
          "Session_id": "dummySessionId"
       }
    },
     "aggs": {
        "max_time": {
           "max": {
             "field": "Time"
            }
         },
         "min_time":{
            "min": {
              "field": "Time"
            }
         }
      }
    }
  </code></pre>
  
  <p>But what I exact want is (max_time - min_time)
  How to write the ES query for the same????</p>