Last active
August 17, 2017 07:06
-
-
Save sajidzaman/009d1acb3f1e433c6e852cb249956c5f to your computer and use it in GitHub Desktop.
Aggregation in Elastic search
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
Each Aggregation makes buckets, it shows the number of documents | |
GET /vehicles/cars/_search | |
{ | |
"aggs": { | |
"popular_cars" : { | |
"terms" : { | |
"field" : "make.keyword" | |
}, | |
"aggs" : { | |
"avg_price": { | |
"avg": { | |
"field" : "price" | |
} | |
} | |
} | |
} | |
}, | |
"sort" :[ | |
] | |
} | |
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
GET /vehicles/cars/_search | |
{ | |
"size": 0, | |
"query" :{ | |
"match": {"color": "red"} | |
}, | |
"aggs": { | |
"popular_cars" : { | |
"terms" : { | |
"field" : "make.keyword" | |
}, | |
"aggs" : { | |
"stats_on_price": { | |
"stats": { | |
"field" : "price" | |
} | |
} | |
} | |
} | |
} | |
} |
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
GET /vehicles/cars/_search | |
{ | |
"query" :{ | |
"match": {"color": "red"} | |
}, | |
"aggs": { | |
"popular_cars" : { | |
"terms" : { | |
"field" : "make.keyword" | |
}, | |
"aggs" : { | |
"avg_price": { | |
"avg": { | |
"field" : "price" | |
} | |
}, | |
"max_price": { | |
"max": { | |
"field" : "price" | |
} | |
}, | |
"min_price": { | |
"min": { | |
"field" : "price" | |
} | |
} | |
} | |
} | |
} | |
} |
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
GET /vehicles/cars/_search | |
{ | |
"size": 0, | |
"query" :{ | |
"match": {"color": "red"} | |
}, | |
"aggs": { | |
"popular_cars" : { | |
"terms" : { | |
"field" : "make.keyword" | |
}, | |
"aggs" : { | |
"sold_date_ranges": { | |
"range": { | |
"field" : "sold", | |
"ranges": [ | |
{ "from" : "2016-01-01", "to": "2016-05-18" }, | |
{ "from" : "2016-05-08", "to": "2017-01-01" } | |
] | |
}, | |
"aggs" :{ | |
"avg_price" :{ | |
"avg" : { | |
"field": "price" | |
} | |
} | |
} | |
} | |
} | |
} | |
} | |
} |
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
GET /vehicles/cars/_search | |
{ | |
"size": 0, | |
"query" :{ | |
"match": {"color": "red"} | |
}, | |
"aggs": { | |
"popular_cars" : { | |
"terms" : { | |
"field" : "make.keyword", | |
"order": {"avg_price": "desc"} | |
}, | |
"aggs" :{ | |
"avg_price" :{ | |
"avg" : { | |
"field": "price" | |
} | |
} | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment