From c005e6b983037867fe2e54b98d92f1b235401fdf Mon Sep 17 00:00:00 2001 From: Ioana Tagirta Date: Wed, 22 Oct 2025 21:03:39 +0200 Subject: [PATCH 1/2] Enable score function in release builds Co-authored-by: Tommaso Teofili --- .../esql/_snippets/functions/layout/score.md | 2 +- .../esql/functions-operators/search-functions.md | 3 +++ .../esql/kibana/definition/functions/score.json | 2 +- muted-tests.yml | 3 --- .../xpack/esql/plugin/ScoreFunctionIT.java | 2 -- .../xpack/esql/action/EsqlCapabilities.java | 2 +- .../esql/expression/function/EsqlFunctionRegistry.java | 4 ++-- .../expression/function/fulltext/FullTextFunction.java | 4 +--- .../function/fulltext/FullTextWritables.java | 4 +--- .../xpack/esql/expression/function/fulltext/Score.java | 2 +- .../xpack/esql/analysis/VerifierTests.java | 9 +++------ .../esql/expression/function/fulltext/ScoreTests.java | 7 ------- .../esql/optimizer/LogicalPlanOptimizerTests.java | 4 ---- .../esql/optimizer/PhysicalPlanOptimizerTests.java | 10 ---------- 14 files changed, 14 insertions(+), 44 deletions(-) diff --git a/docs/reference/query-languages/esql/_snippets/functions/layout/score.md b/docs/reference/query-languages/esql/_snippets/functions/layout/score.md index b2fa5e09baeac..66c7342184f44 100644 --- a/docs/reference/query-languages/esql/_snippets/functions/layout/score.md +++ b/docs/reference/query-languages/esql/_snippets/functions/layout/score.md @@ -2,7 +2,7 @@ ## `SCORE` [esql-score] ```{applies_to} -stack: development +stack: preview 9.3.0 serverless: preview ``` diff --git a/docs/reference/query-languages/esql/functions-operators/search-functions.md b/docs/reference/query-languages/esql/functions-operators/search-functions.md index 1e3bfc8986e1b..670c2f3318c96 100644 --- a/docs/reference/query-languages/esql/functions-operators/search-functions.md +++ b/docs/reference/query-languages/esql/functions-operators/search-functions.md @@ -52,6 +52,9 @@ for information on the limitations of full text search. :::{include} ../_snippets/functions/layout/qstr.md ::: +:::{include} ../_snippets/functions/layout/score.md +::: + % TERM is currently a hidden feature % To make it visible again, uncomment this and the line in lists/search-functions.md diff --git a/docs/reference/query-languages/esql/kibana/definition/functions/score.json b/docs/reference/query-languages/esql/kibana/definition/functions/score.json index 4772093e349d9..ace99710c5fde 100644 --- a/docs/reference/query-languages/esql/kibana/definition/functions/score.json +++ b/docs/reference/query-languages/esql/kibana/definition/functions/score.json @@ -21,5 +21,5 @@ "FROM books METADATA _score\n| WHERE match(title, \"Return\") AND match(author, \"Tolkien\")\n| EVAL first_score = score(match(title, \"Return\"))" ], "preview" : true, - "snapshot_only" : true + "snapshot_only" : false } diff --git a/muted-tests.yml b/muted-tests.yml index 550be4d453dcc..750a27f083075 100644 --- a/muted-tests.yml +++ b/muted-tests.yml @@ -294,9 +294,6 @@ tests: - class: org.elasticsearch.xpack.esql.expression.function.fulltext.ScoreTests method: testSerializationOfSimple {TestCase=} issue: https://github.com/elastic/elasticsearch/issues/131334 -- class: org.elasticsearch.xpack.esql.analysis.VerifierTests - method: testMatchInsideEval - issue: https://github.com/elastic/elasticsearch/issues/131336 - class: org.elasticsearch.packaging.test.DockerTests method: test071BindMountCustomPathWithDifferentUID issue: https://github.com/elastic/elasticsearch/issues/120917 diff --git a/x-pack/plugin/esql/src/internalClusterTest/java/org/elasticsearch/xpack/esql/plugin/ScoreFunctionIT.java b/x-pack/plugin/esql/src/internalClusterTest/java/org/elasticsearch/xpack/esql/plugin/ScoreFunctionIT.java index 99f861420046c..e14a31f6e00be 100644 --- a/x-pack/plugin/esql/src/internalClusterTest/java/org/elasticsearch/xpack/esql/plugin/ScoreFunctionIT.java +++ b/x-pack/plugin/esql/src/internalClusterTest/java/org/elasticsearch/xpack/esql/plugin/ScoreFunctionIT.java @@ -14,7 +14,6 @@ import org.elasticsearch.plugins.Plugin; import org.elasticsearch.xpack.esql.VerificationException; import org.elasticsearch.xpack.esql.action.AbstractEsqlIntegTestCase; -import org.elasticsearch.xpack.esql.action.EsqlCapabilities; import org.elasticsearch.xpack.kql.KqlPlugin; import org.junit.Before; @@ -30,7 +29,6 @@ public class ScoreFunctionIT extends AbstractEsqlIntegTestCase { @Before public void setupIndex() { - assumeTrue("can run this only when score() function is enabled", EsqlCapabilities.Cap.SCORE_FUNCTION.isEnabled()); createAndPopulateIndex(); } diff --git a/x-pack/plugin/esql/src/main/java/org/elasticsearch/xpack/esql/action/EsqlCapabilities.java b/x-pack/plugin/esql/src/main/java/org/elasticsearch/xpack/esql/action/EsqlCapabilities.java index 8dae1d8865efe..73c79a8b22ee3 100644 --- a/x-pack/plugin/esql/src/main/java/org/elasticsearch/xpack/esql/action/EsqlCapabilities.java +++ b/x-pack/plugin/esql/src/main/java/org/elasticsearch/xpack/esql/action/EsqlCapabilities.java @@ -1118,7 +1118,7 @@ public enum Cap { /** * score function */ - SCORE_FUNCTION(Build.current().isSnapshot()), + SCORE_FUNCTION, /** * Support for the SAMPLE command diff --git a/x-pack/plugin/esql/src/main/java/org/elasticsearch/xpack/esql/expression/function/EsqlFunctionRegistry.java b/x-pack/plugin/esql/src/main/java/org/elasticsearch/xpack/esql/expression/function/EsqlFunctionRegistry.java index 2f4d72338b4fc..e9a0442fad1df 100644 --- a/x-pack/plugin/esql/src/main/java/org/elasticsearch/xpack/esql/expression/function/EsqlFunctionRegistry.java +++ b/x-pack/plugin/esql/src/main/java/org/elasticsearch/xpack/esql/expression/function/EsqlFunctionRegistry.java @@ -516,7 +516,8 @@ private static FunctionDefinition[][] functions() { def(Match.class, tri(Match::new), "match"), def(MultiMatch.class, MultiMatch::new, "multi_match"), def(QueryString.class, bi(QueryString::new), "qstr"), - def(MatchPhrase.class, tri(MatchPhrase::new), "match_phrase") }, + def(MatchPhrase.class, tri(MatchPhrase::new), "match_phrase"), + def(Score.class, uni(Score::new), "score") }, // time-series functions new FunctionDefinition[] { def(Rate.class, uni(Rate::new), "rate"), @@ -548,7 +549,6 @@ private static FunctionDefinition[][] snapshotFunctions() { def(Delay.class, Delay::new, "delay"), def(First.class, bi(First::new), "first"), def(Last.class, bi(Last::new), "last"), - def(Score.class, uni(Score::new), Score.NAME), def(Term.class, bi(Term::new), "term"), def(CosineSimilarity.class, CosineSimilarity::new, "v_cosine"), def(DotProduct.class, DotProduct::new, "v_dot_product"), diff --git a/x-pack/plugin/esql/src/main/java/org/elasticsearch/xpack/esql/expression/function/fulltext/FullTextFunction.java b/x-pack/plugin/esql/src/main/java/org/elasticsearch/xpack/esql/expression/function/fulltext/FullTextFunction.java index 7ab187fe060fa..7b2914dd94551 100644 --- a/x-pack/plugin/esql/src/main/java/org/elasticsearch/xpack/esql/expression/function/fulltext/FullTextFunction.java +++ b/x-pack/plugin/esql/src/main/java/org/elasticsearch/xpack/esql/expression/function/fulltext/FullTextFunction.java @@ -15,7 +15,6 @@ import org.elasticsearch.compute.operator.ScoreOperator; import org.elasticsearch.index.IndexMode; import org.elasticsearch.index.query.QueryBuilder; -import org.elasticsearch.xpack.esql.action.EsqlCapabilities; import org.elasticsearch.xpack.esql.capabilities.PostAnalysisPlanVerificationAware; import org.elasticsearch.xpack.esql.capabilities.PostOptimizationVerificationAware; import org.elasticsearch.xpack.esql.capabilities.RewriteableAware; @@ -227,8 +226,7 @@ private static void checkFullTextQueryFunctions(LogicalPlan plan, Failures failu failures.add( fail( ftf, - "[{}] {} is only supported in WHERE and STATS commands" - + (EsqlCapabilities.Cap.SCORE_FUNCTION.isEnabled() ? ", or in EVAL within score(.) function" : ""), + "[{}] {} is only supported in WHERE and STATS commands or in EVAL within score(.) function", ftf.functionName(), ftf.functionType() ) diff --git a/x-pack/plugin/esql/src/main/java/org/elasticsearch/xpack/esql/expression/function/fulltext/FullTextWritables.java b/x-pack/plugin/esql/src/main/java/org/elasticsearch/xpack/esql/expression/function/fulltext/FullTextWritables.java index c846da085040b..7ea2d56fbcc6e 100644 --- a/x-pack/plugin/esql/src/main/java/org/elasticsearch/xpack/esql/expression/function/fulltext/FullTextWritables.java +++ b/x-pack/plugin/esql/src/main/java/org/elasticsearch/xpack/esql/expression/function/fulltext/FullTextWritables.java @@ -25,13 +25,11 @@ public static List getNamedWriteables() { entries.add(MultiMatch.ENTRY); entries.add(Kql.ENTRY); entries.add(MatchPhrase.ENTRY); + entries.add(Score.ENTRY); if (EsqlCapabilities.Cap.TERM_FUNCTION.isEnabled()) { entries.add(Term.ENTRY); } - if (EsqlCapabilities.Cap.SCORE_FUNCTION.isEnabled()) { - entries.add(Score.ENTRY); - } if (EsqlCapabilities.Cap.DECAY_FUNCTION.isEnabled()) { entries.add(Decay.ENTRY); } diff --git a/x-pack/plugin/esql/src/main/java/org/elasticsearch/xpack/esql/expression/function/fulltext/Score.java b/x-pack/plugin/esql/src/main/java/org/elasticsearch/xpack/esql/expression/function/fulltext/Score.java index 148557df2daf6..0e7fd2bd1287c 100644 --- a/x-pack/plugin/esql/src/main/java/org/elasticsearch/xpack/esql/expression/function/fulltext/Score.java +++ b/x-pack/plugin/esql/src/main/java/org/elasticsearch/xpack/esql/expression/function/fulltext/Score.java @@ -47,7 +47,7 @@ public class Score extends Function implements EvaluatorMapper { @FunctionInfo( returnType = "double", preview = true, - appliesTo = { @FunctionAppliesTo(lifeCycle = FunctionAppliesToLifecycle.DEVELOPMENT) }, + appliesTo = { @FunctionAppliesTo(lifeCycle = FunctionAppliesToLifecycle.PREVIEW, version = "9.3.0") }, description = "Scores an expression. Only full text functions will be scored. Returns scores for all the resulting docs.", examples = { @Example(file = "score-function", tag = "score-function") } ) diff --git a/x-pack/plugin/esql/src/test/java/org/elasticsearch/xpack/esql/analysis/VerifierTests.java b/x-pack/plugin/esql/src/test/java/org/elasticsearch/xpack/esql/analysis/VerifierTests.java index b35258978b72c..343d817ea4db4 100644 --- a/x-pack/plugin/esql/src/test/java/org/elasticsearch/xpack/esql/analysis/VerifierTests.java +++ b/x-pack/plugin/esql/src/test/java/org/elasticsearch/xpack/esql/analysis/VerifierTests.java @@ -1279,8 +1279,7 @@ public void testWeightedAvg() { public void testMatchInsideEval() throws Exception { assertEquals( - "1:36: [:] operator is only supported in WHERE and STATS commands" - + (EsqlCapabilities.Cap.SCORE_FUNCTION.isEnabled() ? ", or in EVAL within score(.) function" : "") + "1:36: [:] operator is only supported in WHERE and STATS commands or in EVAL within score(.) function" + "\n" + "line 1:36: [:] operator cannot operate on [title], which is not a field from an index mapping", error("row title = \"brown fox\" | eval x = title:\"fox\" ") @@ -1448,8 +1447,7 @@ private void checkFullTextFunctionsOnlyAllowedInWhere(String functionName, Strin + functionName + "] " + functionType - + " is only supported in WHERE and STATS commands" - + (EsqlCapabilities.Cap.SCORE_FUNCTION.isEnabled() ? ", or in EVAL within score(.) function" : "") + + " is only supported in WHERE and STATS commands or in EVAL within score(.) function" ) ); assertThat( @@ -1469,8 +1467,7 @@ private void checkFullTextFunctionsOnlyAllowedInWhere(String functionName, Strin + functionName + "] " + functionType - + " is only supported in WHERE and STATS commands" - + (EsqlCapabilities.Cap.SCORE_FUNCTION.isEnabled() ? ", or in EVAL within score(.) function" : "") + + " is only supported in WHERE and STATS commands or in EVAL within score(.) function" ) ); } diff --git a/x-pack/plugin/esql/src/test/java/org/elasticsearch/xpack/esql/expression/function/fulltext/ScoreTests.java b/x-pack/plugin/esql/src/test/java/org/elasticsearch/xpack/esql/expression/function/fulltext/ScoreTests.java index 74b2dffe2e4c4..3326a12830dd7 100644 --- a/x-pack/plugin/esql/src/test/java/org/elasticsearch/xpack/esql/expression/function/fulltext/ScoreTests.java +++ b/x-pack/plugin/esql/src/test/java/org/elasticsearch/xpack/esql/expression/function/fulltext/ScoreTests.java @@ -10,12 +10,10 @@ import com.carrotsearch.randomizedtesting.annotations.Name; import com.carrotsearch.randomizedtesting.annotations.ParametersFactory; -import org.elasticsearch.xpack.esql.action.EsqlCapabilities; import org.elasticsearch.xpack.esql.core.expression.Expression; import org.elasticsearch.xpack.esql.core.tree.Source; import org.elasticsearch.xpack.esql.expression.function.FunctionName; import org.elasticsearch.xpack.esql.expression.function.TestCaseSupplier; -import org.junit.BeforeClass; import java.util.ArrayList; import java.util.List; @@ -28,11 +26,6 @@ @FunctionName("score") public class ScoreTests extends AbstractMatchFullTextFunctionTests { - @BeforeClass - public static void init() { - assumeTrue("can run this only when score() function is enabled", EsqlCapabilities.Cap.SCORE_FUNCTION.isEnabled()); - } - public ScoreTests(@Name("TestCase") Supplier testCaseSupplier) { this.testCase = testCaseSupplier.get(); } diff --git a/x-pack/plugin/esql/src/test/java/org/elasticsearch/xpack/esql/optimizer/LogicalPlanOptimizerTests.java b/x-pack/plugin/esql/src/test/java/org/elasticsearch/xpack/esql/optimizer/LogicalPlanOptimizerTests.java index 4bf0b1ae635f5..0c90d2493dd72 100644 --- a/x-pack/plugin/esql/src/test/java/org/elasticsearch/xpack/esql/optimizer/LogicalPlanOptimizerTests.java +++ b/x-pack/plugin/esql/src/test/java/org/elasticsearch/xpack/esql/optimizer/LogicalPlanOptimizerTests.java @@ -214,8 +214,6 @@ public class LogicalPlanOptimizerTests extends AbstractLogicalPlanOptimizerTests private static final LiteralsOnTheRight LITERALS_ON_THE_RIGHT = new LiteralsOnTheRight(); public void testEvalWithScoreImplicitLimit() { - assumeTrue("[SCORE] function is only available in snapshot builds", EsqlCapabilities.Cap.SCORE_FUNCTION.isEnabled()); - var plan = plan(""" FROM test | EVAL s = SCORE(MATCH(last_name, "high")) @@ -229,8 +227,6 @@ public void testEvalWithScoreImplicitLimit() { } public void testEvalWithScoreExplicitLimit() { - assumeTrue("[SCORE] function is only available in snapshot builds", EsqlCapabilities.Cap.SCORE_FUNCTION.isEnabled()); - var plan = plan(""" FROM test | EVAL s = SCORE(MATCH(last_name, "high")) diff --git a/x-pack/plugin/esql/src/test/java/org/elasticsearch/xpack/esql/optimizer/PhysicalPlanOptimizerTests.java b/x-pack/plugin/esql/src/test/java/org/elasticsearch/xpack/esql/optimizer/PhysicalPlanOptimizerTests.java index 40acba1df02af..bf30125f65110 100644 --- a/x-pack/plugin/esql/src/test/java/org/elasticsearch/xpack/esql/optimizer/PhysicalPlanOptimizerTests.java +++ b/x-pack/plugin/esql/src/test/java/org/elasticsearch/xpack/esql/optimizer/PhysicalPlanOptimizerTests.java @@ -670,8 +670,6 @@ public void testTripleExtractorPerField() { * [[QueryBuilderAndTags{queryBuilder=[null], tags=[]}]] */ public void testEvalWithScoreImplicitLimit() { - assumeTrue("[SCORE] function is only available in snapshot builds", EsqlCapabilities.Cap.SCORE_FUNCTION.isEnabled()); - var plan = physicalPlan(""" FROM test | EVAL s = SCORE(MATCH(first_name, "foo")) @@ -704,8 +702,6 @@ public void testEvalWithScoreImplicitLimit() { * [[QueryBuilderAndTags{queryBuilder=[null], tags=[]}]] */ public void testEvalWithScoreExplicitLimit() { - assumeTrue("[SCORE] function is only available in snapshot builds", EsqlCapabilities.Cap.SCORE_FUNCTION.isEnabled()); - var plan = physicalPlan(""" FROM test | EVAL s = SCORE(MATCH(first_name, "foo")) @@ -747,8 +743,6 @@ public void testEvalWithScoreExplicitLimit() { * }], tags=[]}]] **/ public void testEvalWithScoreAndFilterOnEval() { - assumeTrue("[SCORE] function is only available in snapshot builds", EsqlCapabilities.Cap.SCORE_FUNCTION.isEnabled()); - var plan = physicalPlan(""" FROM test | EVAL s = SCORE(MATCH(first_name, "foo")) @@ -802,8 +796,6 @@ public void testEvalWithScoreAndFilterOnEval() { * }], tags=[]}]] **/ public void testEvalWithScoreAndGenericFilter() { - assumeTrue("[SCORE] function is only available in snapshot builds", EsqlCapabilities.Cap.SCORE_FUNCTION.isEnabled()); - var plan = physicalPlan(""" FROM test | EVAL s = SCORE(MATCH(first_name, "foo")) @@ -855,8 +847,6 @@ public void testEvalWithScoreAndGenericFilter() { * }], tags=[]}]] */ public void testEvalWithScoreForTopN() { - assumeTrue("[SCORE] function is only available in snapshot builds", EsqlCapabilities.Cap.SCORE_FUNCTION.isEnabled()); - var plan = physicalPlan(""" FROM test | EVAL s = SCORE(MATCH(first_name, "foo")) From 75107a5b0fb0ce1efb3f3c61f096991903ff902c Mon Sep 17 00:00:00 2001 From: Ioana Tagirta Date: Wed, 22 Oct 2025 21:15:12 +0200 Subject: [PATCH 2/2] Update docs/changelog/136988.yaml --- docs/changelog/136988.yaml | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 docs/changelog/136988.yaml diff --git a/docs/changelog/136988.yaml b/docs/changelog/136988.yaml new file mode 100644 index 0000000000000..7d69e924b17c2 --- /dev/null +++ b/docs/changelog/136988.yaml @@ -0,0 +1,5 @@ +pr: 136988 +summary: Enable score function in release builds +area: ES|QL +type: feature +issues: []