Created
February 11, 2024 19:17
-
-
Save SeRGei93/d3b29ff6b67c9756e1416d32427b53fe to your computer and use it in GitHub Desktop.
elastic facet filter
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Mapping | |
{ | |
"properties": { | |
"id": { | |
"type": "integer" | |
}, | |
"active": { | |
"type": "keyword" | |
}, | |
"canBuy": { | |
"type": "keyword" | |
}, | |
"sections": { | |
"type": "integer" | |
}, | |
"textFacets": { | |
"type": "nested", | |
"properties": { | |
"id": { | |
"type": "keyword" | |
}, | |
"value": { | |
"type": "keyword" | |
} | |
} | |
} | |
} | |
} | |
Query | |
{ | |
"query": { | |
"bool": { | |
"must": [ | |
{ | |
"terms": { | |
"active": [ | |
true | |
] | |
} | |
}, | |
{ | |
"terms": { | |
"canBuy": [ | |
true | |
] | |
} | |
}, | |
{ | |
"terms": { | |
"sections": [ | |
3233 | |
] | |
} | |
} | |
] | |
} | |
}, | |
"post_filter": { | |
"bool": { | |
"filter": [ | |
{ | |
"nested": { | |
"path": "textFacets", | |
"query": { | |
"bool": { | |
"filter": [ | |
{ | |
"term": { | |
"textFacets.id": { | |
"value": "obem-vstroennoy-pamyati" | |
} | |
} | |
}, | |
{ | |
"terms": { | |
"textFacets.value": [ | |
"32-gb", | |
"128-gb" | |
] | |
} | |
} | |
] | |
} | |
} | |
} | |
}, | |
{ | |
"nested": { | |
"path": "textFacets", | |
"query": { | |
"bool": { | |
"filter": [ | |
{ | |
"term": { | |
"textFacets.id": { | |
"value": "brand" | |
} | |
} | |
}, | |
{ | |
"terms": { | |
"textFacets.value": [ | |
"apple", | |
"samsung" | |
] | |
} | |
} | |
] | |
} | |
} | |
} | |
} | |
] | |
} | |
}, | |
"aggs": { | |
"agg_brand": { | |
"nested": { | |
"path": "textFacets" | |
}, | |
"aggs": { | |
"brand_filter": { | |
"filter": { | |
"nested": { | |
"path": "textFacets", | |
"query": { | |
"bool": { | |
"must": [ | |
{ | |
"term": { | |
"textFacets.id": "obem-vstroennoy-pamyati" | |
} | |
}, | |
{ | |
"terms": { | |
"textFacets.value": [ | |
"256-gb", | |
"512-gb" | |
] | |
} | |
} | |
] | |
} | |
} | |
} | |
}, | |
"aggs": { | |
"properties": { | |
"terms": { | |
"field": "textFacets.id", | |
"size": 100 | |
}, | |
"aggs": { | |
"values": { | |
"terms": { | |
"field": "textFacets.value", | |
"size": 100 | |
} | |
} | |
} | |
} | |
} | |
} | |
} | |
} | |
}, | |
"size": 10 | |
} | |
Result | |
{ | |
"took": 51, | |
"timed_out": false, | |
"_shards": { | |
"total": 1, | |
"successful": 1, | |
"skipped": 0, | |
"failed": 0 | |
}, | |
"hits": { | |
"total": { | |
"value": 123, | |
"relation": "eq" | |
}, | |
"max_score": 3.0, | |
"hits": [ | |
{ | |
"_index": "patio_products-202402082334", | |
"_id": "198711", | |
"_score": 3.0, | |
"_source": { | |
"id": 198711, | |
"active": true, | |
"canBuy": true, | |
"sectionId": 3233, | |
"textFacets": [ | |
{ | |
"id": "kolichestvo-yader-processora", | |
"value": [ | |
"8" | |
] | |
}, | |
{ | |
"id": "obem-operativnoy-pamyati", | |
"value": [ | |
"4-gb" | |
] | |
}, | |
{ | |
"id": "obem-vstroennoy-pamyati", | |
"value": [ | |
"128-gb" | |
] | |
}, | |
{ | |
"id": "brand", | |
"value": [ | |
"samsung" | |
] | |
} | |
] | |
} | |
}, | |
{ | |
"_index": "patio_products-202402082334", | |
"_id": "198712", | |
"_score": 3.0, | |
"_source": { | |
"id": 198712, | |
"active": true, | |
"canBuy": true, | |
"sectionId": 3233, | |
"textFacets": [ | |
{ | |
"id": "kolichestvo-yader-processora", | |
"value": [ | |
"8" | |
] | |
}, | |
{ | |
"id": "obem-operativnoy-pamyati", | |
"value": [ | |
"4-gb" | |
] | |
}, | |
{ | |
"id": "obem-vstroennoy-pamyati", | |
"value": [ | |
"256-gb" | |
] | |
}, | |
{ | |
"id": "brand", | |
"value": [ | |
"apple" | |
] | |
} | |
] | |
} | |
}, | |
{ | |
"_index": "patio_products-202402082334", | |
"_id": "198714", | |
"_score": 3.0, | |
"_source": { | |
"id": 198712, | |
"active": true, | |
"canBuy": true, | |
"sectionId": 3233, | |
"textFacets": [ | |
{ | |
"id": "kolichestvo-yader-processora", | |
"value": [ | |
"4" | |
] | |
}, | |
{ | |
"id": "obem-operativnoy-pamyati", | |
"value": [ | |
"4-gb" | |
] | |
}, | |
{ | |
"id": "obem-vstroennoy-pamyati", | |
"value": [ | |
"256-gb" | |
] | |
}, | |
{ | |
"id": "brand", | |
"value": [ | |
"samsung" | |
] | |
} | |
] | |
} | |
} | |
] | |
}, | |
"aggregations": { | |
"agg_brand": { | |
"doc_count": 13034, | |
"brand_filter": { | |
"doc_count": 168, | |
"properties": { | |
"doc_count_error_upper_bound": 0, | |
"sum_other_doc_count": 0, | |
"buckets": [ | |
{ | |
"key": "zaschita", | |
"doc_count": 100, | |
"values": { | |
"doc_count_error_upper_bound": 0, | |
"sum_other_doc_count": 0, | |
"buckets": [ | |
{ | |
"key": "ot-vlagi", | |
"doc_count": 64 | |
}, | |
{ | |
"key": "ot-pyli", | |
"doc_count": 60 | |
}, | |
{ | |
"key": "ot-bryzg", | |
"doc_count": 32 | |
}, | |
{ | |
"key": "net", | |
"doc_count": 25 | |
}, | |
{ | |
"key": "ustoychivost-k-carapinam", | |
"doc_count": 25 | |
}, | |
{ | |
"key": "udaroprochnost", | |
"doc_count": 1 | |
} | |
] | |
} | |
}, | |
{ | |
"key": "podderzhka-karty-pamyati", | |
"doc_count": 63, | |
"values": { | |
"doc_count_error_upper_bound": 0, | |
"sum_other_doc_count": 0, | |
"buckets": [ | |
{ | |
"key": "microsdxc", | |
"doc_count": 35 | |
}, | |
{ | |
"key": "microsd", | |
"doc_count": 33 | |
}, | |
{ | |
"key": "microsdhc", | |
"doc_count": 29 | |
}, | |
{ | |
"key": "net", | |
"doc_count": 24 | |
}, | |
{ | |
"key": "nm-card", | |
"doc_count": 4 | |
} | |
] | |
} | |
}, | |
{ | |
"key": "material-korpusa", | |
"doc_count": 5, | |
"values": { | |
"doc_count_error_upper_bound": 0, | |
"sum_other_doc_count": 0, | |
"buckets": [ | |
{ | |
"key": "plastik", | |
"doc_count": 5 | |
} | |
] | |
} | |
} | |
] | |
} | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment