So I am trying to write a query which returns aggregations of facets. So for example (Red: 12, Green: 8, XL : 4 etc) where the numbers are the document counts.
I have been following this article which explains what I am trying to achieve
The difference for me, is I am using nested documents. So instead of having Size, Colour, Fabric as separate objects in the documents, I have a nested facet type (facet name, facet value) so (Colour Red, Size XS) etc.
When a customer filters by Colour & Size. So Colour Red and Size 16 for example. If we use the results aggregations we only get one colour now and one size (Red & 16) as the results are only for Red & 16. So what we need to do is in the aggs, we get all sizes which are red, and we get all colours which are in size 16.
This is my query so far, but when I try and apply a filter to the aggs. To say get me all colours which are size 10, the only results I get back is size 10.
{
"query": {
"bool": {
"must": [
{
"nested": {
"path": "pageRanks",
"query": {
"term": {
"pageRanks.pageId": {
"value": 934,
"_name": "query-pageId"
}
}
}
}
}
]
}
},
"aggs": {
"resellers": {
"nested": {
"path": "facets"
},
"aggs": {
"Color": {
"aggs": {
"Color": {
"terms": {
"field": "facets.keyword",
"size": 10
}
}
},
"filter": {
"bool": {
"filter": [
{
"terms": {
"facets.keywords": [
"Black"
]
}
},
{
"terms": {
"facets.keywords": [
"10"
]
}
}
]
}
}
}
}
}
}
}
Not sure if we going down the wrong route at all, a fresh pair of eyes would be great.
Thanks