First query for getting facets
{
"query": {
"multi_match" : {
"query": "tops",
"fields": ["name^12.1", "brand^20.0"]
}
},
"aggs": {
"attributes": {
"nested": {
"path": "attributes"
},
"aggs": {
"key": {
"terms": {
"field": "attributes.key"
},
"aggs": {
"value": {
"terms": {
"field": "attributes.value"
}
}
}
}
}
}
}
}
response:
{
"took": 826,
"hits": {
"total": 29513,
"max_score": 102.30364,
"hits": [
....
]
},
"aggregations": {
"attributes": {
"doc_count": 82662,
"key": {
"doc_count_error_upper_bound": 766,
"sum_other_doc_count": 42982,
"buckets": [
{
"key": "color_family",
"doc_count": 10875,
"value": {
"doc_count_error_upper_bound": 0,
"sum_other_doc_count": 2520,
"buckets": [
{
"key": "white",
"doc_count": 1996
},
{
"key": "blue",
"doc_count": 1226
},
{
"key": "brown",
"doc_count": 900
},
{
"key": "green",
"doc_count": 862
},
{
"key": "multicolor",
"doc_count": 752
},
{
"key": "red",
"doc_count": 747
},
{
"key": "gray",
"doc_count": 726
},
{
"key": "silver",
"doc_count": 722
},
{
"key": "pink",
"doc_count": 653
},
{
"key": "yellow",
"doc_count": 527
}
]
}
},
{
"key": "paper_color",
"doc_count": 2158,
"value": {
"doc_count_error_upper_bound": 9,
"sum_other_doc_count": 642,
"buckets": [
{
"key": "white",
"doc_count": 802
},
{
"key": "blue",
"doc_count": 208
},
{
"key": "beige",
"doc_count": 116
},
{
"key": "pink",
"doc_count": 112
},
{
"key": "red",
"doc_count": 112
},
{
"key": "brown",
"doc_count": 107
},
{
"key": "gray",
"doc_count": 102
},
{
"key": "green",
"doc_count": 101
},
{
"key": "bright",
"doc_count": 82
},
{
"key": "silver",
"doc_count": 76
}
]
}
},
]
}
}
}
}
query to select a filter
{
"query": {
"bool": {
"must": {
"multi_match" : {
"query": "tops",
"fields": ["name^12.1", "brand^20.0"]
}
},
"filter": {
"bool":{
"must":
[
{"match":{"attributes.key": "color_family"}},
{"match":{"attributes.value": "white"}}
]
}
}
}
},
"aggs": {
"attributes": {
"nested": {
"path": "attributes"
},
"aggs": {
"key": {
"terms": {
"field": "attributes.key"
},
"aggs": {
"value": {
"terms": {
"field": "attributes.value"
}
}
}
}
}
}
}
}
second one gets all the color family and white ones and not the white in color_family
{
"took": 139,
"hits": {
"total": 2002,
"max_score": 102.30364,
"hits": [
......
]
},
"aggregations": {
"attributes": {
"doc_count": 9146,
"key": {
"doc_count_error_upper_bound": 72,
"sum_other_doc_count": 3495,
"buckets": [
{
"key": "color_family",
"doc_count": 2002,
"value": {
"doc_count_error_upper_bound": 0,
"sum_other_doc_count": 0,
"buckets": [
{
"key": "white",
"doc_count": 1998
},
{
"key": "black",
"doc_count": 1
},
{
"key": "blue",
"doc_count": 1
},
{
"key": "green",
"doc_count": 1
},
{
"key": "multicolor",
"doc_count": 1
},
{
"key": "red",
"doc_count": 1
}
]
}
}
]
}
}
}
}