Skip to content

Instantly share code, notes, and snippets.

@rybesh
Forked from jpountz/start_duration_agg.sh
Created December 7, 2015 14:36
Show Gist options
  • Save rybesh/3e83cc883a6a82e79f34 to your computer and use it in GitHub Desktop.
Save rybesh/3e83cc883a6a82e79f34 to your computer and use it in GitHub Desktop.
DELETE test
PUT test
{
"mappings": {
"test": {
"properties": {
"start": {
"type": "date"
},
"duration": {
"type": "long"
}
}
}
}
}
PUT test/test/1
{
"start": "2015-07-12T09:14:01Z",
"duration": 10000
}
PUT test/test/2
{
"start": "2015-07-12T10:20:50Z",
"duration": 20000
}
PUT test/test/3
{
"start": "2015-07-12T12:00:42Z",
"duration": 5000
}
GET test/_search
{
"aggs": {
"my_histo": {
"date_histogram": {
"script": "start = doc['start'].value; duration = doc['duration'].value * 1000; l = []; for (long i = 0; i < duration; i += interval) { l.add(start + i); }; return l;",
"params": {
"interval": 3600
},
"interval": "hour"
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment