Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions docs/changelog/136988.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
pr: 136988
summary: Enable score function in release builds
area: ES|QL
type: feature
issues: []

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,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
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1123,7 +1123,7 @@ public enum Cap {
/**
* score function
*/
SCORE_FUNCTION(Build.current().isSnapshot()),
SCORE_FUNCTION,

/**
* Support for the SAMPLE command
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -526,7 +526,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[] {
defTS(Rate.class, Rate::new, "rate"),
Expand Down Expand Up @@ -559,7 +560,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"),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.PostOptimizationPlanVerificationAware;
import org.elasticsearch.xpack.esql.capabilities.PostOptimizationVerificationAware;
Expand Down Expand Up @@ -211,8 +210,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()
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,11 @@ public static List<NamedWriteableRegistry.Entry> 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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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") }
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1413,8 +1413,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\" ")
Expand Down Expand Up @@ -1582,8 +1581,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(
Expand All @@ -1603,8 +1601,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"
)
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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.TestCase> testCaseSupplier) {
this.testCase = testCaseSupplier.get();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -217,8 +217,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"))
Expand All @@ -232,8 +230,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"))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -683,8 +683,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"))
Expand Down Expand Up @@ -717,8 +715,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"))
Expand Down Expand Up @@ -760,8 +756,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"))
Expand Down Expand Up @@ -815,8 +809,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"))
Expand Down Expand Up @@ -868,8 +860,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"))
Expand Down