Skip to content

Instantly share code, notes, and snippets.

@markharwood
Created May 12, 2017 08:11
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 markharwood/5f217da5b42525a886b3e405214e9cd7 to your computer and use it in GitHub Desktop.
Save markharwood/5f217da5b42525a886b3e405214e9cd7 to your computer and use it in GitHub Desktop.
Sort by average - not for use on high cardinality fields!!!!
DELETE test
PUT test
{
"mappings": {
"ticker":{
"properties": {
"asset_type":{
"type":"keyword"
},
"price":{
"type":"float"
}
}
}
}
}
POST /test/ticker/_bulk
{"index": {}}
{"asset_type": "foo","price":10}
{"index": {}}
{"asset_type": "foo","price":20}
{"index": {}}
{"asset_type": "bar","price":1}
{"index": {}}
{"asset_type": "bar","price":10000}
POST test/_search
{
"size": 0,
"aggs": {
"name": {
"terms": {
"field": "asset_type",
"size" : 100,
"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