Skip to content

Instantly share code, notes, and snippets.

@kosho
Created June 14, 2018 07:14
Show Gist options
  • Save kosho/da03fe8a03bf8daef24719c0c7481da2 to your computer and use it in GitHub Desktop.
Save kosho/da03fe8a03bf8daef24719c0c7481da2 to your computer and use it in GitHub Desktop.
# Rollup NYC Taxi index
# Create a rollup job
# It works for the documents already and going to be indexed
PUT _xpack/rollup/job/nyc-taxi-yellow
{
"index_pattern": "nyc-taxi-yellow-*",
"rollup_index": "nyc-taxi-yellow_rollup",
"cron": "*/30 * * * * ?",
"page_size" :1000,
"groups" : {
"date_histogram": {
"field": "@timestamp",
"interval": "1h",
"delay": "7d"
},
"terms": {
"fields": ["PULocationID_t.keyword"]
}
},
"metrics": [
{
"field": "passenger_count",
"metrics": ["sum"]
}
]
}
# Start the job
POST _xpack/rollup/job/nyc-taxi-yellow/_start
# Search upon the original index
GET nyc-taxi-yellow-*/_search
{
"size": 0,
"aggs": {
"1": {
"date_histogram": {
"field": "@timestamp",
"interval": "1d"
},
"aggs": {
"2": {
"sum": {
"field": "passenger_count"
}
}
}
}
}
}
# Search upon the rollup index
GET nyc-taxi-yellow_rollup/_rollup_search
{
"size": 0,
"aggs": {
"2": {
"sum": {
"field": "passenger_count"
}
}
}
}
GET nyc-taxi-yellow_rollup/_rollup_search
{
"size": 0,
"aggs": {
"1": {
"date_histogram": {
"field": "@timestamp",
"interval": "1d"
},
"aggs": {
"2": {
"sum": {
"field": "passenger_count"
}
}
}
}
}
}
# Stop the job
POST _xpack/rollup/job/nyc-taxi-yellow/_stop
# Delete the job
DELETE _xpack/rollup/job/nyc-taxi-yellow
# Delete the rollup index
DELETE nyc-taxi-yellow_rollup
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment