本記事でやること
v8.16.0からGAとなったRetrieverを使いo19sのLTRプラグインによるRescoreクエリを構築し、動作の検証をします。
対象読者
- o19sのLTRプラグインを利用している方
- RetrieverによるRescoreクエリを検討している方
検証環境
- Elasticsearch v9.0.1
- o19s v1.5.11-es9.0.1
背景
v8.12で実装されたElasticのLTRモデルを活用する場合、Enterpriseライセンスが必要になります。Enterpriseライセンス以外のユーザーがLTRによるRescoreを行う場合、o19sのLTRプラグインが選択肢となります。
参考: Elastic self-managed subscriptions
以下のPRが取り込まれたことによりv8.18からRescore Retrieverが利用できるようになりました。そこで本記事ではo19sのLTRプラグインがRescore retrieverで活用できるかどうかを検証します。
検証
Elasticsearchクラスタの構築
本記事では、https://github.com/o19s/hello-ltr レポジトリを使用してLTRプラグインが利用できる環境を構築します。
詳細は以下の記事を参照してください。
Rescore retrieverの実行
Rescore retrieverは子retrieverからの出力をリランキングします。以下のようretrieverの中にさらにretrieverを入れ子にします。今回は、Standard retrieverからの結果をリランクするような形になっております。
GET tmdb/_search
{
"retriever": {
"rescorer": {
"rescore": {
"window_size": 10,
"query": {
"rescore_query": {
"sltr": {
"params": {},
"model": "latest"
}
}
}
},
"retriever": {
"standard": {
"query": {
"match": {"title": "Batman"}
}
}
}
}
}
}
以下のように結果が返ってくることが確認できました。
{
"took": 4,
"timed_out": false,
"_shards": {
"total": 1,
"successful": 1,
"skipped": 0,
"failed": 0
},
"hits": {
"total": {
"value": 30,
"relation": "eq"
},
"max_score": 12.573205,
"hits": [
{
"_index": "tmdb",
"_id": "251519",
"_score": 12.573205,
"_source": {
"id": "251519",
"title": "Son of Batman",
"overview": "Batman learns that he has a violent, unruly pre-teen son with Talia al Ghul named Damian Wayne who is secretly being raised by Ra's al Ghul and the League of Assassins. When Ra's al Ghul apparently dies after a battle with Deathstroke, Batman must work to stop his long-lost son from taking revenge and guiding him to a righteous path, in addition to the chance for the pair to truly acknowledging each other as family.",
"tagline": "Vengeance runs in the blood.",
"directors": [
"Ethan Spaulding"
],
"cast": "Jason O'Mara Stuart Allan Thomas Gibson Morena Baccarin Giancarlo Esposito David McCallum Xander Berkeley Sean Maher Dee Bradley Baker",
"genres": [
"Animation",
"Action",
"Adventure"
],
"release_date": "2014-04-20",
"release_year": "2014",
"poster_path": "https://image.tmdb.org/t/p/w185/j3SFJqZPeeB9g5JMU7UFLgEqj2T.jpg",
"vote_average": 6.8,
"vote_count": 242
}
},
{
"_index": "tmdb",
"_id": "2661",
"_score": 3.4645238,
"_source": {
"id": "2661",
"title": "Batman",
"overview": "The Dynamic Duo faces four super-villains who plan to hold the world for ransom with the help of a secret invention that instantly dehydrates people.",
"tagline": "He's Here Big As Life In A Real Bat-Epic",
"directors": [
"Leslie H. Martinson"
],
"cast": "Adam West Burt Ward Lee Meriwether Cesar Romero Burgess Meredith Frank Gorshin Alan Napier Neil Hamilton Stafford Repp Madge Blake Reginald Denny Milton Frome Gil Perkins Dick Crockett George Sawaya Van Williams Jack LaLanne Arthur Tovey",
"genres": [
"Family",
"Adventure",
"Comedy",
"Science Fiction",
"Crime"
],
"release_date": "1966-07-30",
"release_year": "1966",
"poster_path": "https://image.tmdb.org/t/p/w185/udDVJXtAFsQ8DimrXkVFqy4DGEQ.jpg",
"vote_average": 6,
"vote_count": 153
}
},
...省略
さらにretrieverを入れ子にすることで多段にRescoreをすることも可能です。
GET tmdb/_search
{
"retriever": {
"rescorer": {
"rescore": {
"query": {
"rescore_query": {
"sltr":{
"params": {},
"model": "classic"
}
}
}
},
"retriever": {
"rescorer": {
"rescore": {
"window_size": 10,
"query": {
"rescore_query": {
"sltr": {
"params": {},
"model": "latest"
}
}
}
},
"retriever": {
"standard": {
"query": {
"match": {
"title": "Batman"
}
}
}
}
}
}
}
}
}
ライセンス毎に使えるretriever
現時点(2025/08/05)では、以下のretrieverはEnterpriseライセンスのみとなります。
まとめ
本記事ではRescore retrieverでo19sのLTRプラグインを活用する方法を紹介しました。retrieverを入れ子にすることで多段にRescoreをすることもできます。また、retrieverによってはEnterpriseライセンスでのみしか利用できないものもあります。