-
-
Save markharwood/5f217da5b42525a886b3e405214e9cd7 to your computer and use it in GitHub Desktop.
Sort by average - not for use on high cardinality fields!!!!
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
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