Skip to content

Instantly share code, notes, and snippets.

@jpountz
Created July 24, 2015 14:57
Show Gist options
  • Save jpountz/cebb8452648c36099cee to your computer and use it in GitHub Desktop.
Save jpountz/cebb8452648c36099cee 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"
}
}
}
}
@zahodi
Copy link

zahodi commented Nov 21, 2017

I have a question about your script. You return "l" to elasticsearch. How does elasticsearch use that value?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment