I have following mappings
PUT prod_nested
{
"mappings": {
"default": {
"properties": {
"pkey": {
"type": "keyword"
},
"original_price": {
"type": "float"
},
"tags": {
"type": "nested",
"properties": {
"category": {
"type": "text",
"fields": {
"keyword": {
"type": "keyword",
"ignore_above": 30
}
}
},
"attribute": {
"type": "text",
"fields": {
"keyword": {
"type": "keyword",
"ignore_above": 30
}
}
},
"original_price": {
"type": "float"
}
}
}
}
}
}
}
I am trying to do aggregation similar to following sql query
select tag_attribute,
tag_category,
avg(original_price)
FROM products
GROUP BY tag_category, tag_attribute
I am able to get the group by part using nested aggregation, but not able to get avg(original_price).
GET prod_nested/_search?size=0
{
"aggs": {
"tags": {
"nested": {
"path": "tags"
},
"aggs": {
"categories": {
"terms": {
"field": "tags.category.keyword",
"size": 30
},
"aggs": {
"attributes": {
"terms": {
"field": "tags.attribute.keyword",
"size": 30
}
}
}
}
}
}
}
}
Thanks, in advance.