title: Elasticsearch sum by sum from max
body: <p>I need some help with finding total number of messages from all the topics. </p>
  
  <p>The document below has +million number of topics,partition and offsets. </p>
  
  <p>I need to get total number of offsets :</p>
  
  <pre><code>"kafka": {
    "partition": {
      "topic": {
        "name": "testTopic20181206"
      },
      "broker": {
        "id": 4,
        "address": "localhost:9092"
      },
      "partition": {
        "insync_replica": true,
        "id": 0,
        "leader": 3,
        "replica": 1
      },
      "offset": {
        "newest": 17330676,
        "oldest": 0
     }
    }
  </code></pre>
  
  <p>Query that i am using is : </p>
  
  <pre><code>  GET metricbeat-6*/_search
    {
      "size": 0,
      "aggs": {
        "Topic": {
          "terms": {
            "field": "kafka.partition.topic.name",
            "size": 10000
          },
          "aggregations": {
            "Partition": {
              "terms": {
                "field": "kafka.partition.partition.id"
              },
              "aggregations": {
              "Partition": {
                "max": {
                  "field": "kafka.partition.offset.newest"
                }
              }
              }
  
            }
          }
        }
    }
  </code></pre>
  
  <p>}</p>