title: Elastic Search: Selecting multiple vlaues in aggregates
body: <p>In Elastic Search I have the following index with 'allocated_bytes', 'total_bytes' and other fields:</p>
  
  <pre><code>{
    "_index" : "metrics-blockstore_capacity-2017_06",
    "_type" : "datapoint",
    "_id" : "AVzHwgsi9KuwEU6jCXy5",
    "_score" : 1.0,
    "_source" : {
      "timestamp" : 1498000001000,
      "resource_guid" : "2185d15c-5298-44ac-8646-37575490125d",
      "allocated_bytes" : 1.159196672E9,
      "resource_type" : "machine",
      "total_bytes" : 1.460811776E11,
      "machine" : "2185d15c-5298-44ac-8646-37575490125d"
    }
  </code></pre>
  
  <p>I have the following query to 
  1)get a point for 30 minute interval using date-histogram 
  2)group by field on resource_guid. 
  3)max aggregate to find the max value. </p>
  
  <pre><code>{
    "size": 0,
    "query": {
      "bool": {
    "must": [
      {
        "range": {
          "timestamp": {
            "gte": 1497992400000,
            "lte": 1497996000000
          }
        }
      }
    ]
  }
  },
  "aggregations": {
  "groupByTime": {
    "date_histogram": {
      "field": "timestamp",
      "interval": "30m",
      "order": {
        "_key": "desc"
      }
    },
    "aggregations": {
      "groupByField": {
        "terms": {
          "size": 1000,
          "field": "resource_guid"
        },
        "aggregations": {
          "maxValue": {
            "max": {
              "field": "allocated_bytes"
            }
           }
        }
      },
      "sumUnique": {
        "sum_bucket": {
          "buckets_path": "groupByField&gt;maxValue"
        }
      }
    }
  }
  </code></pre>
  
  <p>}
  }</p>
  
  <p>But with this query I am able to get only allocated_bytes, but I need to have both allocated_bytes and total_bytes at the result point. </p>
  
  <p>Following is the result from the above query:</p>
  
  <pre><code>{
      "key_as_string" : "2017-06-20T21:00:00.000Z",
      "key" : 1497992400000,
      "doc_count" : 9,
      "groupByField" : {
        "doc_count_error_upper_bound" : 0,
        "sum_other_doc_count" : 0,
        "buckets" : [ {
          "key" : "2185d15c-5298-44ac-8646-37575490125d",
          "doc_count" : 3,
          "maxValue" : {
            "value" : 1.156182016E9
          }
        }, {
          "key" : "c3513cdd-58bb-4f8e-9b4c-467230b4f6e2",
          "doc_count" : 3,
          "maxValue" : {
            "value" : 1.156165632E9
          }
        }, {
          "key" : "eff13403-9737-4d08-9dca-fb6c12c3a6fa",
          "doc_count" : 3,
          "maxValue" : {
            "value" : 1.156182016E9
          }
        } ]
      },
      "sumUnique" : {
        "value" : 3.468529664E9
      }
    }
  </code></pre>
  
  <p>I do need both allocated_bytes and total_bytes. How do I get multiple fields( allocated_bytes, total_bytes) for each point?</p>
  
  <p>For example:</p>
  
  <pre><code>"sumUnique" : {
        "Allocatedvalue" : 3.468529664E9,
        "TotalValue" : 9.468529664E9
      }
  </code></pre>
  
  <p>or like this:</p>
  
  <pre><code>"allocatedBytessumUnique" : {
        "value" : 3.468529664E9
      }
  "totalBytessumUnique" : {
        "value" : 9.468529664E9
      },
  </code></pre>