Hi,
Say I have a schema:-
{
"product": {
"mappings": {
"main": {
"properties": {
...
"skus": {
"type": "nested",
"properties": {
...
"attributes": {
"type": "nested",
"properties": {
"key": {
"type": "text",
"fields": {
"keyword": {
"type": "keyword",
"ignore_above": 256
}
}
},
"value": {
"type": "text",
"fields": {
"keyword": {
"type": "keyword",
"ignore_above": 256
}
}
}
}
}
}
}
}
}
}
}
}
So a product has sku's and sku's have attributes (key/value).
I can get the aggregation of attribute keys with the values for a product like so:-
"aggs": {
"attributes": {
"nested": {
"path": "skus.attributes"
},
"aggs": {
"attribute": {
"terms": {
"field": "skus.attributes.key.keyword"
},
"aggs": {
"value": {
"terms": {
"field": "skus.attributes.value.keyword"
}
}
}
}
}
}
}
but this gives me the counts of sku's, rather than products:-
{
"aggregations": {
"attributes": {
"doc_count": 20,
"attribute": {
...
"buckets": [
{
"key": "foo",
"doc_count": 20,
"value": {
...
"buckets": [
{
"key": "bar",
"doc_count": 10
},
{
"key": "barr",
"doc_count": 10
}
]
}
}
]
}
}
}
}
I also need to be able to filter the aggregates by an 'attribute'. ie, Get the attributes and their values where a product has a attribute 'size' and value 'medium'.
Is this possible?
Any help/guidance would be much appreciated.
Thanks
Ben