Skip to content

Commit 62b4faa

Browse files
committed
Docs: Clarify constraints on scripted similarities. (#31076)
Scripted similarities provide a lot of flexibility but they still need to obey some rules to not confuse Lucene.
1 parent 86e5f00 commit 62b4faa

File tree

1 file changed

+12
-2
lines changed

1 file changed

+12
-2
lines changed

docs/reference/index-modules/similarity.asciidoc

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -326,7 +326,18 @@ Which yields:
326326
// TESTRESPONSE[s/"took": 12/"took" : $body.took/]
327327
// TESTRESPONSE[s/OzrdjxNtQGaqs4DmioFw9A/$body.hits.hits.0._node/]
328328

329-
You might have noticed that a significant part of the script depends on
329+
WARNING: While scripted similarities provide a lot of flexibility, there is
330+
a set of rules that they need to satisfy. Failing to do so could make
331+
Elasticsearch silently return wrong top hits or fail with internal errors at
332+
search time:
333+
334+
- Returned scores must be positive.
335+
- All other variables remaining equal, scores must not decrease when
336+
`doc.freq` increases.
337+
- All other variables remaining equal, scores must not increase when
338+
`doc.length` increases.
339+
340+
You might have noticed that a significant part of the above script depends on
330341
statistics that are the same for every document. It is possible to make the
331342
above slightly more efficient by providing an `weight_script` which will
332343
compute the document-independent part of the score and will be available
@@ -491,7 +502,6 @@ GET /index/_search?explain=true
491502
492503
////////////////////
493504

494-
495505
Type name: `scripted`
496506

497507
[float]

0 commit comments

Comments
 (0)