ES6.1.2+LTR常用DSL

6453 ワード

ES6.1.2+LTR常用DSL


https://elasticsearch-learning-to-rank.readthedocs.io/LTRプラグインで使用するDSLは古いバージョンで、新しいバージョンの多くの内容が変更されました.新しいバージョンのフィーチャーセット構築部分はes 6で以下の形式に変更する必要があります.1.2テストに成功しました.

functionはカラムを返します

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"
  ]
}

LTR構築特別募集

#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}}"
          }
        }
      }
    ]
  }
}

Functionを追加scoreの特徴

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.0 
							
							
								 -2.0 
							
						
						
							 -1.990678310394287 
						
					
					
						 2 
						 8.814796 
						
							 2 
							 7.3007236 
							
								 -1.9988385438919067 
							
							
								 -1.9554523229599 
							
						
						
							 1 
							 7.0104666 
							
								 -1.739653468132019 
							
							
								 -1.516905426979065 
							
						
					
				
				
					 2.0 
				
			
			
				 1 
				 10.686367 
				
					 2.0 
				
				
					 2.0 
				
			
		
	

"""
    }
  }
}

現在のモデルの表示

GET _ltr/_model/my_ranklib_model

search use 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"
  ]
}