2
0

More than 5 years have passed since last update.

Elasticsearch: field_value_factorのmodifierによる増加の違いをグラフ化した

Posted at

ElasticsearchのFunctionScoreQueryにはfieldの値をscoreに関連づけられるfield_value_factor functionがあります。

field_value_factorにはデフォルト(none) + 9種類のmodifierが指定でき、field_valueに特殊な計算をした値をscoreとすることができます。

modifier score計算
none field_value
log log(field_value)
log1p log(1 + field_value)
log2p log(2 + field_value)
ln ln(field_value)
ln1p ln(1 + field_value)
ln2p ln(2 + field_value)
square (field_value)^2
sqrt √(field_value)
reciprocal 1 / field_value

いずれも簡単な計算ですが頭の中で考えるより目で見たほうがわかりやすいのでグラフにしました。
グラフには square を含めていません。指数関数なので他に比べ増加率が高すぎグラフが見づらくなるためです。

field値 1 〜 10の範囲の場合

Screen Shot 0029-01-22 at 20.17.28.png

field_value 1 〜 1000の範囲の場合

noneは除いています。log3種とln3種はそれぞれ一本にまとまって見えています。

Screen Shot 0029-01-22 at 19.55.33.png

log1pとln1pの使いどころ

公式ドキュメントに記述があり、field_value = 0に対して log, ln を指定すると例外を発生させるのでそれを回避するために使用するとのことです。

Keep in mind that taking the log() of 0, or the square root of a negative number
is an illegal operation, and an exception will be thrown. Be sure to limit the
values of the field with a range filter to avoid this, or use log1p and
ln1p.

log2p, ln2pについては言及がありませんが -1か自然数の値をもつfieldに使用するんでしょうか。

2
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
0