# Weigheted average on es-5.0.0

**URL:** <https://discuss.elastic.co/t/weigheted-average-on-es-5-0-0/67871>\
**Category:** Elasticsearch\
**Created:** [December 2, 2016, 3:17pm UTC](https://discuss.elastic.co/t/weigheted-average-on-es-5-0-0/67871 "2016-12-02T15:17:54Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Hilal](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/hilal/32/7684_2.png) [@Hilal](https://discuss.elastic.co/u/Hilal)\
**Post date:** [December 2, 2016, 3:17pm UTC](https://discuss.elastic.co/t/weigheted-average-on-es-5-0-0/67871/1 "2016-12-02T15:17:54Z")

</div>

I tried other things:

```
GET titubb56k/ihale/_search 
{
  "aggs": {
    "myAggr": {
      "terms": {
        "field": "UrunNo",
        "order": { "weightedAvg": "desc"}
      },  
      "aggs": {
          "weightedAvg": { "avg" : { "script" : "[values: doc['BirimFiyat'].value, weights: doc['Adet'].value]" }}
       } } } }

```

But I have error:

```
{
  "error": {
    "root_cause": [
      {
        "type": "parsing_exception",
        "reason": "Unexpected token VALUE_STRING [script] in [weightedAvg].",
        "line": 9,
        "col": 49
      }
    ],
    "type": "parsing_exception",
    "reason": "Unexpected token VALUE_STRING [script] in [weightedAvg].",
    "line": 9,
    "col": 49
  },
  "status": 400
}

```

I don't understand.  
Can you help me please?

---

<div class="post-metadata">

**Author:** ![colings86](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/colings86/32/44960_2.png) [@colings86](https://discuss.elastic.co/u/colings86)\
**Post date:** [December 2, 2016, 3:57pm UTC](https://discuss.elastic.co/t/weigheted-average-on-es-5-0-0/67871/2 "2016-12-02T15:57:59Z")

</div>

It looks like you have already got a topic for this here: [Weighted Average and aggregations](https://discuss.elastic.co/t/weigheted-average-and-aggregations/67755/2)

Please do not open duplicate topics.

Closing this topic in favour of [Weighted Average and aggregations](https://discuss.elastic.co/t/weigheted-average-and-aggregations/67755/2) where you have already had some responses

---

<div class="post-metadata">

**Author:** ![colings86](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/colings86/32/44960_2.png) [@colings86](https://discuss.elastic.co/u/colings86)\
**Post date:** [December 2, 2016, 3:58pm UTC](https://discuss.elastic.co/t/weigheted-average-on-es-5-0-0/67871/3 "2016-12-02T15:58:03Z")

</div>


