Skip to content

Instantly share code, notes, and snippets.

Created December 19, 2013 08:34
Show Gist options
  • Save anonymous/8036182 to your computer and use it in GitHub Desktop.
Save anonymous/8036182 to your computer and use it in GitHub Desktop.
ticket_id: 1
event: red_wedding
organization: freys
sold_at: 2013-12-01T12:00
price: 400
---
ticket_id: 2
event: red_wedding
organization: freys
sold_at: 2013-12-01T12:01
price: 400
---
ticket_id: 3
event: red_wedding
organization: freys
sold_at: 2013-12-01T12:03
price: 400
---
ticket_id: 4
event: afterparty
organization: freys
sold_at: 2013-12-01T12:03
price: 600
---
ticket_id: 5
event: purple_wedding
organization: lannisters
sold_at: 2013-12-04T12:00
price: 500
---
ticket_id: 6
event: red_wedding
organization: freys
sold_at: 2013-12-04T12:00
price: 1000
---
#!/bin/bash
export ELASTICSEARCH_ENDPOINT="http://localhost:9200"
# Create indexes
curl -XPUT "$ELASTICSEARCH_ENDPOINT/play" -d '{
"settings": {}
}'
# Index documents
curl -XPOST "$ELASTICSEARCH_ENDPOINT/_bulk?refresh=true" -d '
{"index":{"_index":"play","_type":"type"}}
{"ticket_id":1,"event":"red_wedding","organization":"freys","sold_at":"2013-12-01T12:00","price":400}
{"index":{"_index":"play","_type":"type"}}
{"ticket_id":2,"event":"red_wedding","organization":"freys","sold_at":"2013-12-01T12:01","price":400}
{"index":{"_index":"play","_type":"type"}}
{"ticket_id":3,"event":"red_wedding","organization":"freys","sold_at":"2013-12-01T12:03","price":400}
{"index":{"_index":"play","_type":"type"}}
{"ticket_id":4,"event":"afterparty","organization":"freys","sold_at":"2013-12-01T12:03","price":600}
{"index":{"_index":"play","_type":"type"}}
{"ticket_id":5,"event":"purple_wedding","organization":"lannisters","sold_at":"2013-12-04T12:00","price":500}
{"index":{"_index":"play","_type":"type"}}
{"ticket_id":6,"event":"red_wedding","organization":"freys","sold_at":"2013-12-04T12:00","price":1000}
{"index":{"_index":"play","_type":"type"}}
{}
'
# Do searches
curl -XPOST "$ELASTICSEARCH_ENDPOINT/_search?pretty" -d '
{
"size": 0,
"aggregations": {
"organization": {
"terms": {
"field": "organization",
"order": {
"revenue.sum": "desc"
}
},
"aggs": {
"revenue": {
"stats": {
"field": "price"
}
},
"event": {
"terms": {
"field": "event",
"order": {
"_count": "desc"
}
},
"aggs": {
"sales": {
"date_histogram": {
"field": "sold_at",
"interval": "1d"
},
"aggs": {
"price": {
"extended_stats": {
"field": "price"
}
}
}
}
}
}
}
}
}
}
'
# Auto generated by Found's Play-tool at 2013-12-19T09:34:00+01:00
version: 0
title: Ticket sales performance
description: ""
size: 0
aggregations:
organization:
terms:
field: organization
order:
revenue.sum: desc
aggs:
revenue:
stats:
field: price
event:
terms:
field: event
order:
_count: desc
aggs:
sales:
date_histogram:
field: sold_at
interval: 1d
aggs:
price:
extended_stats:
field: price
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment