title: Elastic Search weighted average aggs before version 7.5
body: <p>I need to get the weighted average of 2 fields in the elastic search, weighted average aggregation got introduced in ES v7.5, but i'm supposed to use a much older version (v5.x).</p>
  
  <p>Can someone help me out to get the ES query for something like below in v5.x</p>
  
  <pre><code>sum of (grade X weight) / sum of weights
  
  {
      "size": 0,
      "aggs" : {
          "weighted_grade": {
              "weighted_avg": {
                  "value": {
                      "field": "grade"
                  },
                  "weight": {
                      "field": "weight"
                  }
              }
          }
      }
  }
  </code></pre>
  
  <p>Thanks in advance.</p>