Skip to content

Instantly share code, notes, and snippets.

@mkhludnev
Created February 11, 2024 21:28
Show Gist options
  • Save mkhludnev/d2179e1eda45cc1556f04158515b18c4 to your computer and use it in GitHub Desktop.
Save mkhludnev/d2179e1eda45cc1556f04158515b18c4 to your computer and use it in GitHub Desktop.
nested aggregation elastic
POST https://localhost:9200/nagga/_search
Content-Type: application/json
Authorization: Basic
{
"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
}
####
HTTP/1.1 200 OK
X-elastic-product: Elasticsearch
content-type: application/json
content-length: 1311
{
"took": 246,
"timed_out": false,
"_shards": {
"total": 1,
"successful": 1,
"skipped": 0,
"failed": 0
},
"hits": {
"total": {
"value": 1,
"relation": "eq"
},
"max_score": 1.0,
"hits": [
{
"_index": "nagga",
"_id": "198711",
"_score": 1.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"
]
}
]
}
}
]
},
"aggregations": {
"agg_brand": {
"doc_count": 16,
"brand_filter": {
"doc_count": 3,
"properties": {
"doc_count_error_upper_bound": 0,
"sum_other_doc_count": 0,
"buckets": [
{
"key": "brand",
"doc_count": 3,
"values": {
"doc_count_error_upper_bound": 0,
"sum_other_doc_count": 0,
"buckets": [
{
"key": "Sanyo",
"doc_count": 1
},
{
"key": "apple",
"doc_count": 1
},
{
"key": "samsung",
"doc_count": 1
}
]
}
}
]
}
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment