Skip to content

Instantly share code, notes, and snippets.

@galleon
Created December 4, 2014 17:23
Show Gist options
  • Save galleon/1f1498b016125fbcb9cf to your computer and use it in GitHub Desktop.
Save galleon/1f1498b016125fbcb9cf to your computer and use it in GitHub Desktop.
ES date & aggregations
curl -XPOST "http://localhost:9200/myindex/"
curl -XPOST "http://localhost:9200/myindex/travel/_mapping" -d '
{
"travel": {
"properties": {
"end_date": {
"format": "dateOptionalTime",
"type": "date"
},
"start_date": {
"format": "dateOptionalTime",
"type": "date"
}
}
}
}'
curl -XPOST "http://localhost:9200/myindex/travel/" -d '
{
"start_date":"2013-09-11T11:50:00.000Z",
"end_date":"2013-09-11T13:08:00.000Z"
}'
curl -XGET 'http://localhost:9200/myindex/travel/_search?pretty' -d '
{
"aggs": {
"duration": {
"histogram": {
"interval": 1,
"script": "(doc['end_date']-doc['start_date'])/3600"
}
}
}
}'
curl -XGET 'http://localhost:9200/myindex/travel/_search?pretty' -d '
{
"aggs": {
"duration": {
"histogram": {
"interval": 1,
"script": "(doc['end_date'].value-doc['start_date'].value)/3600"
}
}
}
}
'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment