elasticsearch plugin address
https://coding.net/u/bywei/p/elasticsearch-feature-scoring/git
Use Cases
You can use this plugin to calculate two features like correlation scores:
- Personalized search;
- Find similar products;
- Products Recommended;
Generate plugin from code
- git clone https://git.coding.net/bywei/elasticsearch-feature-scoring.git
- MVN Cleaning Kit - DskipTests
- Create feature score plugin dircectoy like ${ES_HOME/plugins/featurescore}
- Copy target/release/elasticsearch-feature-scoring-2.1.0.zip to your plugins directory and extract it
- restart elasticsearch
script parameters
- customSortField : optional , a vector field in the index to store the file;
- customSorts : **not NULL requires customSortField**, condition, a map<string, int>;
- sortFields : optional , condition, a map<string, int>;
- version : the version of the vector, if not empty, the version of the file vector that should match (|, like "20170331|0.1" if version is used, the value of this field should start with "$VERSION");
about
- QQ:1940775885
- WX:jiaivr
- Website: http://www.bywei.cn
example
Create a test indicator
PUT /hotelplatform
{
"mappings": {
"hotelDayPrice": {
"properties": {
"hotelId": {
"type": "long"
},
"day": {
"type": "long"
}
}
}
},
"settings": {
"index": {
"number_of_shards": 1,
"number_of_replicas": 0
}
}
}
index of some files
POST /hotelplatform/hotelDayPrice/1
{
"hotelId": "32195",
"day": "1493740800000"
}
POST /hotelplatform/hotelDayPrice/2
{
"hotelId": "32250",
"day": "1493740800000"
}
POST /hotelplatform/hotelDayPrice/3
{
"hotelId": "32217",
"day": "1493740800000"
}
normal search
POST /hotelplatform/_search
{
"query": {
"match": {
"hotelId": "32217"
}
}
}
The result is:
{
"took": 8,
"timed_out": false,
"_shards": {
"total": 1,
"successful": 1,
"failed": 0
},
"hits": {
"total": 3,
"max_score": 0.14181954,
"hits": [
{
"_index": "hotelplatform",
"_type": "hotelDayPrice",
"_id": "2",
"_score": 0.14181954,
"_source": {
"hotelId": "32250",
"day": "1493740800000"
}
},
{
"_index": "hotelplatform",
"_type": "hotelDayPrice",
"_id": "1",
"_score": 0.1273061,
"_source": {
"hotelId": "32195",
"day": "1493740800000"
}
},
{
"_index": "hotelplatform",
"_type": "hotelDayPrice",
"_id": "3",
"_score": 0.1273061,
"_source": {
"hotelId": "32217",
"day": "1493740800000"
}
}
]
}
}
Search whith feature scores sortFields
{
"from" : 0,
"size" : 10,
"query" : {
"bool" : {
"must" : [ {
"term" : {
"channelCode" : "JJ_INTEGRATION_WEIXIN"
}
}, {
"term" : {
"day" : 1493827200000
}
} ]
}
},
"_source" : {
"includes" : [ "hotelId", "orderScore", "hotelScore", "serviceScore"],
"excludes" : [ ]
},
"sort" : [ {
"_script" : {
"script" : {
"inline" : "feature-scoring",
"lang" : "native",
"params" : {
"sortFields" : {
"orderScore" : 0.3,
"hotelScore" : 0.2,
"serviceScore" : 0.5
}
}
},
"type" : "number",
"reverse" : true
}
}]
}
其结果是:排序(orderScore * 0.3 + hotelScore * 0.2 + serviceScore * 0.5)
搜索与特征分数customSorts和customSortField
POST /hotelplatform/_search
{
"from": 0,
"size": 100,
"query": {
"bool": {
"must": [
{
"term": {
"day": 1493740800000
}
}
]
}
},
"_source": {
"includes": [
"hotelId",
"day"
],
"excludes": []
},
"sort": [
{
"_script": {
"script": {
"inline": "feature-scoring",
"lang": "native",
"params": {
"customSortField": "hotelId",
"customSorts": {
"32195": 200,
"32217": 300
}
}
},
"type": "number",
"reverse": true
}
}
]
}
其结果是:
{
"took": 36,
"timed_out": false,
"_shards": {
"total": 5,
"successful": 5,
"failed": 0
},
"hits": {
"total": 12,
"max_score": null,
"hits": [
{
"_index": "hotelplatform",
"_type": "hotelDayPrice",
"_id": "32217JJ_INTEGRATION_WEIXIN1493740800000",
"_score": null,
"_routing": "32217",
"_parent": "32217",
"_source": {
"hotelId": 32217,
"day": 1493740800000
},
"sort": [
1,
300,
440
]
},
{
"_index": "hotelplatform",
"_type": "hotelDayPrice",
"_id": "32195JJ_INTEGRATION_WEIXIN1493740800000",
"_score": null,
"_routing": "32195",
"_parent": "32195",
"_source": {
"hotelId": 32195,
"day": 1493740800000
},
"sort": [
1,
200,
554
]
},
{
"_index": "hotelplatform",
"_type": "hotelDayPrice",
"_id": "32250JJ_INTEGRATION_WEIXIN1493740800000",
"_score": null,
"_routing": "32250",
"_parent": "32250",
"_source": {
"hotelId": 32250,
"day": 1493740800000
},
"sort": [
1,
0,
596
]
},
{
"_index": "hotelplatform",
"_type": "hotelDayPrice",
"_id": "32216JJ_INTEGRATION_WEIXIN1493740800000",
"_score": null,
"_routing": "32216",
"_parent": "32216",
"_source": {
"hotelId": 32216,
"day": 1493740800000
},
"sort": [
1,
0,
646
]
},
{
"_index": "hotelplatform",
"_type": "hotelDayPrice",
"_id": "32247JJ_INTEGRATION_WEIXIN1493740800000",
"_score": null,
"_routing": "32247",
"_parent": "32247",
"_source": {
"hotelId": 32247,
"day": 1493740800000
},
"sort": [
1,
0,
4079
]
},
{
"_index": "hotelplatform",
"_type": "hotelDayPrice",
"_id": "32219JJ_INTEGRATION_WEIXIN1493740800000",
"_score": null,
"_routing": "32219",
"_parent": "32219",
"_source": {
"hotelId": 32219,
"day": 1493740800000
},
"sort": [
1,
0,
4909
]
},
{
"_index": "hotelplatform",
"_type": "hotelDayPrice",
"_id": "21400JJ_INTEGRATION_WEIXIN1493740800000",
"_score": null,
"_routing": "21400",
"_parent": "21400",
"_source": {
"hotelId": 21400,
"day": 1493740800000
},
"sort": [
0,
0,
1
]
},
{
"_index": "hotelplatform",
"_type": "hotelDayPrice",
"_id": "22292JJ_INTEGRATION_WEIXIN1493740800000",
"_score": null,
"_routing": "22292",
"_parent": "22292",
"_source": {
"hotelId": 22292,
"day": 1493740800000
},
"sort": [
0,
0,
12
]
},
{
"_index": "hotelplatform",
"_type": "hotelDayPrice",
"_id": "22290JJ_INTEGRATION_WEIXIN1493740800000",
"_score": null,
"_routing": "22290",
"_parent": "22290",
"_source": {
"hotelId": 22290,
"day": 1493740800000
},
"sort": [
0,
0,
18
]
},
{
"_index": "hotelplatform",
"_type": "hotelDayPrice",
"_id": "21382JJ_INTEGRATION_WEIXIN1493740800000",
"_score": null,
"_routing": "21382",
"_parent": "21382",
"_source": {
"hotelId": 21382,
"day": 1493740800000
},
"sort": [
0,
0,
150
]
},
{
"_index": "hotelplatform",
"_type": "hotelDayPrice",
"_id": "21440JJ_INTEGRATION_WEIXIN1493740800000",
"_score": null,
"_routing": "21440",
"_parent": "21440",
"_source": {
"hotelId": 21440,
"day": 1493740800000
},
"sort": [
0,
0,
488
]
},
{
"_index": "hotelplatform",
"_type": "hotelDayPrice",
"_id": "20166JJ_INTEGRATION_WEIXIN1493740800000",
"_score": null,
"_routing": "20166",
"_parent": "20166",
"_source": {
"hotelId": 20166,
"day": 1493740800000
},
"sort": [
0,
0,
755
]
}
]
}
}
个性化搜索案例的详细情况
锦江App应用