Skip to content

Instantly share code, notes, and snippets.

@chrisronline
Last active December 10, 2019 18:11
Show Gist options
  • Save chrisronline/836dbbdb594d5848538e412236f32147 to your computer and use it in GitHub Desktop.
Save chrisronline/836dbbdb594d5848538e412236f32147 to your computer and use it in GitHub Desktop.
DELETE my_index
PUT my_index
{
"mappings": {
"properties": {
"timestamp": {
"type": "date"
},
"user": {
"type": "nested",
"properties": {
"first": {
"type": "keyword"
},
"last": {
"type": "keyword"
},
"type": {
"type": "keyword"
},
"id": {
"type": "integer"
}
}
}
}
}
}
PUT my_index/_doc/1
{
"group" : "fans",
"timestamp": "2019-12-10",
"user" : [
{
"first" : "John",
"last" : "Smith",
"type": "employee",
"id": 1
},
{
"first" : "Alice",
"last" : "White",
"type": "employee",
"id": 2
}
]
}
POST my_index/_search?filter_path=aggregations.date_histo.buckets.high_level_bs_value,aggregations.date_histo.buckets.in_nested.types.buckets.bs_value
{
"size": 0,
"aggs": {
"date_histo": {
"date_histogram": {
"field": "timestamp",
"fixed_interval": "10s"
},
"aggs": {
"high_level_stats_data": {
"stats": {
"field": "timestamp"
}
},
"high_level_bs_value": {
"bucket_script": {
"script": "params.max - params.min",
"buckets_path": {
"min": "high_level_stats_data.min",
"max": "high_level_stats_data.max"
}
}
},
"in_nested": {
"nested": {
"path": "user"
},
"aggs": {
"types": {
"terms": {
"field": "user.type",
"size": 10
},
"aggs": {
"stats_data": {
"stats": {
"field": "user.id"
}
},
"bs_value": {
"bucket_script": {
"script": "params.max - params.min",
"buckets_path": {
"min": "stats_data.min",
"max": "stats_data.max"
}
}
}
}
}
}
}
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment