Skip to content

Instantly share code, notes, and snippets.

@hadashiA
Last active March 4, 2016 08:29
Show Gist options
  • Save hadashiA/8f8cd979286655380312 to your computer and use it in GitHub Desktop.
Save hadashiA/8f8cd979286655380312 to your computer and use it in GitHub Desktop.
Elasticsearchを使ってレコメンデーションする ref: http://qiita.com/hadashiA/items/9a418df95f8611c041a2
$ plugin --url 'https://github.com/f-kubotar/elasticsearch-flavor/releases/download/v0.0.2/elasticsearch-flavor-0.0.3.zip' --install flavor
curl -XPOST localhost:9200/my_index -d '{
"mappings" : {
"preference" : {
"preference": {
"properties": {
"user_id": {
"type": "long"
},
"item_id": {
"type": "long"
},
"value": {
"type": "float"
}
}
}
}
}
}'
curl -XPOST 'localhost:9200/my_index/preference/1:101/_update' -d '{
"script" : "ctx._source.value += value",
"params" : {
"user_id" : 1,
"item_id": 101,
"value": 1
}
}'
$ curl 'localhost:9200/my_index/preference/_flavor/similar_items/5803?size=3&similarity=EuclideanDistanceSimilarity'
HTTP/1.1 200 OK
Content-Length: 126
Content-Type: application/json; charset=UTF-8
{
"hits": {
"hits": [
{
"item_id": 40891,
"value": 1.0
},
{
"item_id": 48541,
"value": 1.0
},
{
"item_id": 151,
"value": 1.0
}
],
"total": 3
},
"took": 4
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment