Skip to content

Instantly share code, notes, and snippets.

@spinscale
Created January 18, 2017 14:48
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 spinscale/e52a98e54152f3b884bc1229f6682892 to your computer and use it in GitHub Desktop.
Save spinscale/e52a98e54152f3b884bc1229f6682892 to your computer and use it in GitHub Desktop.
Training Beispiel: SubAggregation - Scripting Terms Aggregation
DELETE nutrition
PUT nutrition/foo/_bulk
{ "index" : {} }
{ "calories" : 100, "name" : "Chips", "category" : "a" }
{ "index" : {} }
{ "calories" : 200, "name" : "Thick Chip", "category" : "a" }
{ "index" : {} }
{ "calories" : 300, "name" : "Marzipan", "category" : "b" }
GET nutrition/_search
{
"size": 0,
"aggs": {
"my_calorie_bucket": {
"terms": {
"field": "category.keyword"
},
"aggs": {
"foo": {
"avg": {
"field": "calories"
}
},
"my_top_hits": {
"top_hits": {
"size": 1
}
}
}
}
}
}
DELETE foo
PUT /foo/bar/_bulk
{ "index" : { "_id" : "alex" } }
{ "name" : "Alex" }
{ "index" : { "_id" : "bert" } }
{ "name" : "Bert" }
{ "index" : {"_id" : "caesar" } }
{ "name" : "Caesar" }
{ "index" : {"_id" : "dagobert" } }
{ "name" : "Dagobert" }
GET foo/_search
{
"size": 0,
"aggs": {
"foo": {
"terms": {
"script": {
"inline" : "doc['name.keyword'].value.substring(0, 1)"
},
"size": 10
}
}
}
}
GET foo/_search
{
"size": 1,
"sort": [
{"name.keyword": "asc"},
{"_uid": "desc"}
]
}
GET foo/_search
{
"size": 1,
"search_after" : [ "Alex", "bar#1" ],
"sort": [
{"name.keyword": "asc"},
{"_uid": "desc"}
]
}
GET foo/_search
{
"size": 1,
"search_after" : [ "Bert", "bar#2" ],
"sort": [
{"name.keyword": "asc"},
{"_uid": "desc"}
]
}
DELETE foo/bar/bert
GET foo/_search
{
"size": 1,
"search_after" : [ "Bert", "bar#2" ],
"sort": [
{"name.keyword": "asc"},
{"_uid": "desc"}
]
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment