紫菩提一个Elasticsearch向量相关性评分插件-GinoBeFunny

发布时间: 5年前 (2017-01-06)浏览: 138
一个Elasticsearch向量相关性评分插件-GinoBeFunny
Use Case
You can use this plugin to calculate the relevance score of the two feature vector, such as:
Personalized Search;
Find similar product;
Product recommendation;
Build Plugin from Code
git clonehttps://github.com/ginobefun/elasticsearch-feature-vector-scoring.git
mvn clean package -DskipTests
create vector scoring plugin directory, such as ${ES_HOME}/plugins/vector-scoring
copy target/releases/elasticsearch-feature-vector-scoring-5.3.0.zip to your plugin directory and unzip it
restart elasticsearch
Script Parameters
field:required, field in index to store the vector of document;
inputFeatureVector:required, the condition vector, a string connected with comma;
version: version of the vector, if it isn't null, it should match the version of the vector of document(if use version, the field value should start with ‘$VERSION|’, such as '20170331|0.1,2.3,-1.6,0.7,-1.3');
baseConstantandfactorConstant: used to calculate the final score, default value are 1. final_score = baseConstant + factorConstant * cos(X, Y)
Example
create a test index
PUT /test{ "mappings": { "product": {"properties": { "productName": { "type": "text"狱锁狂龙2 , "analyzer": "standard" }, "productFeatureVector": { "type": "keyword" }} } }, "settings": { "index": {"number_of_shards": 1,"number_of_replicas": 0 } }}
index some documents
POST /test/product/1{ "productName": "My favorite brand of shoes"徐宝宝事件, "productFeatureVector": "0.1,2.3,-1.6,凌潇潇 0.7,-1.3"}POST /test/product/2{ "productName": "Normal brand of shoes"背德病栋 , "productFeatureVector": "-0.5貂蝉故里 ,1.6,1.1,0.9,0.7"}POST /test/product/3{ "productName": "The shoes I don't like", "productFeatureVector": "1.2,0.1,0.4,-0.2,0.3"}
normal search
POST /test/_search{ "query": { "match": {"productName": "shoes" } }}
the the result is:
{ "took": 8, "timed_out": false, "_shards": { "total": 1, "successful": 1, "failed": 0 }, "hits": { "total": 3, "max_score": 0.14181954玩命对战, "hits": [{ "_index": "test", "_type": "product", "_id": "2", "_score": 0.14181954滨虎 , "_source": { "productName": "Normal brand of shoes", "productFeatureVector": "-0.5石小倩,1.6,1.1,0.9华丽的休假 ,0.7" }},{ "_index": "test", "_type": "product", "_id": "1", "_score": 0.1273061, "_source": { "productName": "My favorite brand of shoes", "productFeatureVector": "0.1,2.3,-1.6,0.7,-1.3" }},{ "_index": "test", "_type": "product", "_id": "3", "_score": 0.1273061, "_source": { "productName": "The shoes I don't like", "productFeatureVector": "1.2,0.1,0.4,-0.2,0.3" }} ] }}
search with feature vector score
POST /test/_search{ "query": { "function_score": {"query": { "match": { "productName": "shoes" }}溜溜吧首页 ,"functions": [ { "script_score": {"script": { "inline": "feature_vector_scoring_script", "lang": "native", "params": { "inputFeatureVector": "0.1,2.3,-1.6,0.7,-1.3", "field": "productFeatureVector" }} } }],"boost_mode": "multiply" } }}
and the result is:
{ "took": 35, "timed_out": false, "_shards": { "total": 1, "successful": 1鬼女红叶御魂 , "failed": 0 }, "hits": { "total": 3, "max_score": 0.2546122, "hits": [{ "_index": "test"惊爆无底洞 , "_type": "product", "_id": "1", "_score": 0.2546122, "_source": { "productName": "My favorite brand of shoes"恶魔契约书 , "productFeatureVector": "0.1,2.3,-1.6,0.7,-1.3" }},{ "_index": "test"京山生活网 , "_type": "product"银票网, "_id": "2"花叶蔓长春 , "_score": 0.17267346, "_source": { "productName": "Normal brand of shoes", "productFeatureVector": "-0.5,1.6,1.1,0.9紫菩提 廖晓琴 ,0.7" }},{ "_index": "test", "_type": "product", "_id": "3", "_score": 0.10233018, "_source": { "productName": "The shoes I don't like", "productFeatureVector": "1.2,0.1,0.4,-0.2华再东 ,0.3" }} ] }}
A personalized search case details
seehttp://ginobefunny.com/post/personalized_search_implemention_based_word2vec_and_elasticsearch/

标签:

上一篇: 车臣问题一个人的旅行,是最好的增值期-美国发现之旅
下一篇: 红谷滩教师招聘【龙风诗韵文学院刊LT2006期】浅蓝总院第六期01分院学员第六课作业专辑(学院版S106期)-龙风诗韵文学

︿