Browse Source

Backport moving scoring in ES|QL out of snapshot into 8.x (#120905)

* Move scoring in ES|QL out of snapshot (#120354)
Tommaso Teofili 8 months ago
parent
commit
791d4c1e17

+ 5 - 0
docs/changelog/120354.yaml

@@ -0,0 +1,5 @@
+pr: 120354
+summary: Move scoring in ES|QL out of snapshot
+area: ES|QL
+type: enhancement
+issues: []

+ 2 - 0
docs/reference/esql/metadata-fields.asciidoc

@@ -20,6 +20,8 @@ supported ones are:
   * <<mapping-ignored-field,`_ignored`>>: the ignored source document fields. The field is of the type
   <<keyword,keyword>>.
 
+  * `_score`: when enabled, the final score assigned to each row matching an ES|QL query. Scoring will be updated when using <<esql-search-functions,full text search functions>>.
+
 To enable the access to these fields, the <<esql-from,`FROM`>> source command needs
 to be provided with a dedicated directive:
 

+ 1 - 1
x-pack/plugin/esql/src/main/java/org/elasticsearch/xpack/esql/action/EsqlCapabilities.java

@@ -599,7 +599,7 @@ public class EsqlCapabilities {
         /**
          * Support the "METADATA _score" directive to enable _score column.
          */
-        METADATA_SCORE(Build.current().isSnapshot()),
+        METADATA_SCORE,
 
         /**
          * Term function

+ 1 - 3
x-pack/plugin/esql/src/main/java/org/elasticsearch/xpack/esql/parser/LogicalPlanBuilder.java

@@ -18,7 +18,6 @@ import org.elasticsearch.dissect.DissectParser;
 import org.elasticsearch.index.IndexMode;
 import org.elasticsearch.transport.RemoteClusterAware;
 import org.elasticsearch.xpack.esql.VerificationException;
-import org.elasticsearch.xpack.esql.action.EsqlCapabilities;
 import org.elasticsearch.xpack.esql.common.Failure;
 import org.elasticsearch.xpack.esql.core.expression.Alias;
 import org.elasticsearch.xpack.esql.core.expression.Attribute;
@@ -280,8 +279,7 @@ public class LogicalPlanBuilder extends ExpressionBuilder {
             for (var c : metadataOptionContext.UNQUOTED_SOURCE()) {
                 String id = c.getText();
                 Source src = source(c);
-                if (MetadataAttribute.isSupported(id) == false // TODO: drop check below once METADATA_SCORE is no longer snapshot-only
-                    || (EsqlCapabilities.Cap.METADATA_SCORE.isEnabled() == false && MetadataAttribute.SCORE.equals(id))) {
+                if (MetadataAttribute.isSupported(id) == false) {
                     throw new ParsingException(src, "unsupported metadata field [" + id + "]");
                 }
                 Attribute a = metadataMap.put(id, MetadataAttribute.create(src, id));