# Aggregate "avg" throwing error "Unknown BaseAggregationBuilder "

**URL:** <https://discuss.elastic.co/t/aggregate-avg-throwing-error-unknown-baseaggregationbuilder/123136>\
**Category:** Elasticsearch\
**Created:** [March 8, 2018, 8:49pm UTC](https://discuss.elastic.co/t/aggregate-avg-throwing-error-unknown-baseaggregationbuilder/123136 "2018-03-08T20:49:17Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![jason\_smith](https://avatars.discourse-cdn.com/v4/letter/j/b5e925/32.png) [@jason\_smith](https://discuss.elastic.co/u/jason_smith)\
**Post date:** [March 8, 2018, 8:49pm UTC](https://discuss.elastic.co/t/aggregate-avg-throwing-error-unknown-baseaggregationbuilder/123136/1 "2018-03-08T20:49:18Z")

</div>

Hello Good folks,

This query is from a sample video tutorial. The sample is not Elasticsearch 6.0 version. I am not sure if this is something to do with the lastest version.

Trying to find the average car price under each make of the car. I am getting "type": "unknown\_named\_object\_exception",  
"reason": "Unknown BaseAggregationBuilder [mycalc\_avgprice]"

```
           GET /vehicles/_search
           {
	              "aggs": {
 	                       "mysearchname": {
        		                 "terms": {
        		                 "field": "make.keyword"
        		                 } },
	                        "aggs": {
	                                    "mycalc_avgprice": {
	                                           "avg": {
	                                                    "field": "price"
	                                            } 
	                                     }
	                        }
	               }
             }
```

---

<div class="post-metadata">

**Author:** ![nik9000](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/nik9000/32/44947_2.png) [@nik9000](https://discuss.elastic.co/u/nik9000)\
**Post date:** [March 8, 2018, 9:34pm UTC](https://discuss.elastic.co/t/aggregate-avg-throwing-error-unknown-baseaggregationbuilder/123136/2 "2018-03-08T21:34:34Z")

</div>

I think you have a misplaced `}`. IThe `aggs` element should be inside of `mysearchname` rather than a sibling to it. What you have right now is trying to interpret `aggs` as the name of a sibling aggregation to `mysearchname` and `mycalc_avgprice` as an aggregation name. Since it _isn't_ an aggregation name Elasticsearch complains about not being able to find that name. The error message is kind of lame so I've filed an [issue](https://github.com/elastic/elasticsearch/issues/28950) about it. I believe I'm the one responsible for making that error message. I'm sorry.

Anyway, this is an example from our docs:

```auto
GET /_search
{
    "aggs" : {
        "genres" : {
            "terms" : {
                "field" : "genre",
                "order" : { "max_play_count" : "desc" }
            },
            "aggs" : {
                "max_play_count" : { "max" : { "field" : "play_count" } }
            }
        }
    }
}

```

And it _ought_ to work. We test the docs. It has `aggs` as a sibling to `terms`.

---

<div class="post-metadata">

**Author:** ![jason\_smith](https://avatars.discourse-cdn.com/v4/letter/j/b5e925/32.png) [@jason\_smith](https://discuss.elastic.co/u/jason_smith)\
**Post date:** [March 8, 2018, 9:41pm UTC](https://discuss.elastic.co/t/aggregate-avg-throwing-error-unknown-baseaggregationbuilder/123136/3 "2018-03-08T21:41:55Z")

</div>

Thank You so much. It works now.

Kind regards

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [April 5, 2018, 9:42pm UTC](https://discuss.elastic.co/t/aggregate-avg-throwing-error-unknown-baseaggregationbuilder/123136/4 "2018-04-05T21:42:19Z")

</div>

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.
