Last active
January 30, 2016 03:16
-
-
Save mrotundo/cd1654f5572fe9276a17 to your computer and use it in GitHub Desktop.
Elasticsearch Behavioral Example Queries
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#### 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