Skip to content

Instantly share code, notes, and snippets.

@jkbnerad
Last active July 8, 2016 11:32
Show Gist options
  • Save jkbnerad/9b49f4e31faeae628181cfb65eb60498 to your computer and use it in GitHub Desktop.
Save jkbnerad/9b49f4e31faeae628181cfb65eb60498 to your computer and use it in GitHub Desktop.
Elasticsearch - top brands
{
"aggs": {
"nested": {
"nested": {
"path": "topBrands"
},
"aggs": {
"filtered": {
"filter": {
"term": {
"topBrands.category": 202
}
},
"aggs": {
"brands": {
"terms": {
"field": "topBrands.name",
"order": {"max_rank" : "desc"},
"size": 31
},
"aggs": {
"hits": {
"top_hits": {
"sort": [
{
"topBrands.rank": {
"order": "desc"
}
}
],
"_source": {
"include": [
"name", "rank"
]
},
"size": 1
}
},
"max_rank" : {
"max" : {"field": "topBrands.rank"}
}
}
}
}
}
}
}
},
"size": 0
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment