Skip to content
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
import com.carrotsearch.randomizedtesting.annotations.ParametersFactory;

import org.apache.http.util.EntityUtils;
import org.elasticsearch.Build;
import org.elasticsearch.Version;
import org.elasticsearch.client.Request;
import org.elasticsearch.client.Response;
Expand All @@ -34,7 +33,6 @@
import org.elasticsearch.xpack.esql.action.EsqlCapabilities;
import org.elasticsearch.xpack.esql.plugin.QueryPragmas;
import org.hamcrest.Matcher;
import org.junit.Before;

import java.io.IOException;
import java.math.BigDecimal;
Expand Down Expand Up @@ -80,17 +78,6 @@ public static List<Object[]> args() throws Exception {

protected FieldExtractorTestCase(MappedFieldType.FieldExtractPreference preference) {
this.preference = preference;
if (preference != null) {
assumeTrue("Requires pragma", Build.current().isSnapshot());
}
}

@Before
public void notOld() {
assumeTrue(
"support changed pretty radically in 8.12 so we don't test against 8.11",
getCachedNodesVersions().stream().allMatch(v -> Version.fromString(v).onOrAfter(Version.V_8_12_0))
);
}

public void testTextField() throws IOException {
Expand Down Expand Up @@ -1766,6 +1753,7 @@ private Map<String, Object> runEsql(String query) throws IOException {
request = request.pragmas(
Settings.builder().put(QueryPragmas.FIELD_EXTRACT_PREFERENCE.getKey(), preference.toString()).build()
);
request.pragmasOk();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we need to guard this for 8.16+ because accept_pragma_risks is only available in 8.16+, and FieldExtractorTestCase can run in a mixed cluster.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good call.

}
return runEsqlSync(request);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,14 @@ public RequestObjectBuilder keepOnCompletion(boolean value) throws IOException {
return this;
}

/**
* Allow sending pragmas even in non-snapshot builds.
*/
public RequestObjectBuilder pragmasOk() throws IOException {
builder.field("accept_pragma_risks", true);
return this;
}

Boolean keepOnCompletion() {
return keepOnCompletion;
}
Expand Down