Skip to content

Instantly share code, notes, and snippets.

@mrotundo
Last active January 30, 2016 03:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mrotundo/cd1654f5572fe9276a17 to your computer and use it in GitHub Desktop.
Save mrotundo/cd1654f5572fe9276a17 to your computer and use it in GitHub Desktop.
Elasticsearch Behavioral Example Queries
#### SETUP INDEX
PUT /actions
#### SETUP MAPPINGS
PUT /actions/_mapping/view
# view
{
"view":{
"properties":{
"customer_id": { "type": "integer" },
"product_id": { "type": "integer" },
"customer_name": { "type": "string","index": "not_analyzed" },
"customer_email": { "type": "string" },
"product_name": { "type": "string","index": "not_analyzed" },
"paid": { "type": "float" },
"timestamp": { "type": "date" }
}
}}
PUT /actions/_mapping/purchase
# purchase
{
"purchase":
{
"properties":{
"customer_id": { "type": "integer" },
"product_id": { "type": "integer" },
"customer_name": { "type": "string","index": "not_analyzed" },
"customer_email": { "type": "string" },
"product_name": { "type": "string","index": "not_analyzed" },
"paid": { "type": "float" },
"timestamp": { "type": "date" }
}
}
}
#determine amounts paid by customers and order by most frequent amount paid
POST /actions/_search
#customer id by most active
{
"size":0,
"aggregations": {
"most_active_customers": {
"terms": {
"field": "customer_name"
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment