Skip to content

Instantly share code, notes, and snippets.

@mattfield11
Last active September 1, 2017 10:45
Show Gist options
  • Save mattfield11/3583e910d9106a4167b31607bd57b89e to your computer and use it in GitHub Desktop.
Save mattfield11/3583e910d9106a4167b31607bd57b89e to your computer and use it in GitHub Desktop.
elasticsearch product recommendation
POST user_purchases/_search?
{
"size": 0,
"query": {
"bool": {
"filter": [
{ "term": { "product_id.raw": "polaroid x1566" }}
]
}
},
"aggs" : {
"recommendations" : {
"significant_terms" : { "field" : "product_id.raw" }
}
}
}
############ RESPONSE ##############
....
"aggregations": {
"recommendations": {
"doc_count": 35,
"buckets": [
{
"key": "polaroid x1566",
"doc_count": 35,
"score": 10852.971428571427,
"bg_count": 35
},
{
"key": "polaroid 2 x 3 film",
"doc_count": 5,
"score": 1107.405247813411,
"bg_count": 7
},
{
"key": "101 tips for great photographs",
"doc_count": 10,
"score": 267.0534834623504,
"bg_count": 116
},
{
"key": "My love affair with instagram",
"doc_count": 4,
"score": 206.62802721088437,
"bg_count": 24
},...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment