https://elasticsearch-learning-to-rank.readthedocs.io/
LTR插件中用的DSL是老的版本,新版本很多内容都改变了,新版本特征集构建部分应改为以下形式,在es6.1.2上测试成功。
GET tmdb/movie/_search
{
"query": {
"function_score": {
"query": {
"match_all": {}
},
"functions": [
{
"script_score": {
"script": "_score +doc['vote_average'].value"
}
}
]
}
},
"_source": [
"original_title",
"id",
"vote_average"
]
}
#more movie features
PUT _ltr/_featureset/more_movie_features
{
"featureset": {
"features": [
{
"name": "body_query",
"params": [
"keywords"
],
"template": {
"match": {
"overview": "{{keywords}}"
}
}
},
{
"name": "title_query",
"params": [
"keywords"
],
"template": {
"match": {
"title": "{{keywords}}"
}
}
}
]
}
}
POST /_ltr/_featureset/more_movie_features/_addfeatures
{
"features": [
{
"name": "user_rating",
"params": [],
"template_language": "mustache",
"template": {
"function_score": {
"query": {
"match_all": {}
},
"functions": [
{
"script_score": {
"script": "doc['vote_average'].value"
}
}
]
}
}
}
]
}
GET tmdb/movie/_search
{
"query": {
"bool": {
"filter": [
{
"terms": {
"_id": [
"7555",
"1370",
"1369"
]
}
},
{
"sltr": {
"_name": "logged_featureset",
"featureset": "more_movie_features",
"params": {
"keywords": "rambo"
}
}
}
]
}
},
"ext": {
"ltr_log": {
"log_specs": {
"name": "log_entry1",
"named_query": "logged_featureset"
}
}
},
"_source": [
"original_title",
"id",
"vote_average"
]
}
POST _ltr/_featureset/more_movie_features/_createmodel
{
"model": {
"name": "my_ranklib_model",
"model": {
"type": "model/ranklib",
"definition": """
## LambdaMART
## No. of trees = 1000
## No. of leaves = 10
## No. of threshold candidates = 256
## Learning rate = 0.1
## Stop early = 100
1
10.357836
2
11.950331
1
6.815881
2
8.725015
1
0.0
2
8.814796
2
7.3007236
1
7.0104666
1
10.686367
"""
}
}
}
GET _ltr/_model/my_ranklib_model
POST tmdb/_search
{
"query": {
"query_string": {
"query": "rambo"
}
},
"rescore":{
"query":{
"rescore_query":{
"sltr":{
"params":{
"keywords":"rambo"
},
"model":"my_ranklib_model"
}
}
}
},
"ext":{
"ltr_log":{
"log_specs":{
"name":"log_entry1",
"rescore_index":0
}
}
}
,
"_source": [
"original_title",
"id",
"vote_average"
]
}
GET tmdb/movie/71508
POST tmdb/_search
{
"query": {
"function_score": {
"field_value_factor": {
"field": "popularity",
"missing": 0
}
}
},
"_source": ["original_title",
"id",
"vote_average",
"popularity"
]
}