Aggregate "avg" throwing error "Unknown BaseAggregationBuilder "

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"
	                                            } 
	                                     }
	                        }
	               }
             }
1 Like

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 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:

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.

4 Likes

Thank You so much. It works now.

Kind regards

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