Oh wait, I found the typing mistake. This query worked:
GET order/_search
{
"size": 0,
"aggs": {
"order": {
"nested": {
"path": "order_items.product"
},
"aggs": {
"product_name" : {
"terms": {
"field": "order_items.product.name"
},
"aggs": {
"avg_price": {
"avg": {
"field": "order_items.product.price"
}
}
}
}
}
}
}
}