Skip to content

Instantly share code, notes, and snippets.

@stephlag
Last active August 29, 2015 14:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save stephlag/7ad8edf1ab6b757be3b3 to your computer and use it in GitHub Desktop.
Save stephlag/7ad8edf1ab6b757be3b3 to your computer and use it in GitHub Desktop.
top hits aggregation on denormalized data
# this search gives me the minimum price for the product
GET /products_den/_search
{
"query": {
"bool": {
"must": [
{"term": {
"productId": {
"value": "9782264045331"
}
}},{
"term": {
"used": {
"value": "false"
}
}
}
]
}
},
"aggs": {
"terms": {
"terms": {
"field": "productId"
},
"aggs": {
"top_tag_hits": {
"top_hits": {
"_source": {
"include": [
"sellerName",
"price",
"new",
"priceInCents"
]
},
"sort": [
{
"priceInCents": {
"order": "asc"
}
}
],
"size" : 10
}
}
}
}
}
}
# This search with additional filter fails
GET /products_den/_search
{
"query": {
"bool": {
"must": [
{
"term": {
"productId": {
"value": "9782264045331"
}
}
}
]
}
},
"aggs": {
"terms": {
"terms": {
"field": "productId"
},
"aggs": {
"only_new": {
"filter": {
"term": {
"used": "false"
}
},
"aggs": {
"top_tag_hits": {
"top_hits": {
"_source": {
"include": [
"sellerName",
"price",
"new",
"priceInCents"
]
},
"sort": [
{
"priceInCents": {
"order": "asc"
}
}
],
"size": 10
}
}
}
}
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment