Skip to content

Commit 55850ba

Browse files
working on getting the tests to pass in bwc mode
1 parent 1664b6b commit 55850ba

File tree

5 files changed

+58
-11
lines changed

5 files changed

+58
-11
lines changed

server/src/main/java/org/elasticsearch/TransportVersions.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -314,6 +314,7 @@ static TransportVersion def(int id) {
314314
public static final TransportVersion ML_INFERENCE_CUSTOM_SERVICE_INPUT_TYPE = def(9_105_0_00);
315315
public static final TransportVersion ML_INFERENCE_SAGEMAKER_ELASTIC = def(9_106_0_00);
316316
public static final TransportVersion SPARSE_VECTOR_FIELD_PRUNING_OPTIONS = def(9_107_0_00);
317+
public static final TransportVersion ESQL_FIXED_INDEX_LIKE = def(9_108_0_00);
317318

318319
/*
319320
* STOP! READ THIS FIRST! No, really,

server/src/main/java/org/elasticsearch/action/search/SearchShardsRequest.java

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
import org.elasticsearch.common.io.stream.StreamInput;
1717
import org.elasticsearch.common.io.stream.StreamOutput;
1818
import org.elasticsearch.core.Nullable;
19+
import org.elasticsearch.index.query.MatchAllQueryBuilder;
1920
import org.elasticsearch.index.query.QueryBuilder;
2021
import org.elasticsearch.tasks.Task;
2122
import org.elasticsearch.tasks.TaskId;
@@ -77,7 +78,16 @@ public void writeTo(StreamOutput out) throws IOException {
7778
super.writeTo(out);
7879
out.writeStringArray(indices);
7980
indicesOptions.writeIndicesOptions(out);
80-
out.writeOptionalNamedWriteable(query);
81+
out.writeOptionalNamedWriteable(
82+
query == null || query.supportsVersion(out.getTransportVersion()) ? query :
83+
/*
84+
* The remote node doesn't support the query we're sending. If this were only
85+
* used for _search this could just fail, but for ESQL it's much more convenient
86+
* if it pretends that the query is MatchAll. ESQL will frequently be able to
87+
* perform the document filtering on the data node in its engine. Slowly.
88+
* But correctly.
89+
*/
90+
new MatchAllQueryBuilder());
8191
out.writeOptionalString(routing);
8292
out.writeOptionalString(preference);
8393
out.writeBoolean(allowPartialSearchResults);

server/src/main/java/org/elasticsearch/index/query/WildcardLikeQueryBuilder.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -215,6 +215,6 @@ protected boolean doEquals(WildcardLikeQueryBuilder other) {
215215

216216
@Override
217217
public TransportVersion getMinimalSupportedVersion() {
218-
return TransportVersions.ZERO;
218+
return TransportVersions.ESQL_FIXED_INDEX_LIKE;
219219
}
220220
}

x-pack/plugin/esql/qa/server/multi-clusters/src/javaRestTest/java/org/elasticsearch/xpack/esql/ccq/MultiClustersIT.java

Lines changed: 40 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
import org.junit.rules.TestRule;
3131

3232
import java.io.IOException;
33+
import java.util.ArrayList;
3334
import java.util.List;
3435
import java.util.Map;
3536
import java.util.Set;
@@ -43,6 +44,9 @@
4344
import static org.hamcrest.Matchers.equalTo;
4445
import static org.hamcrest.Matchers.greaterThanOrEqualTo;
4546
import static org.hamcrest.Matchers.hasKey;
47+
import static org.hamcrest.Matchers.anyOf;
48+
import static org.hamcrest.Matchers.is;
49+
import static org.hamcrest.Matchers.nullValue;
4650

4751
@ThreadLeakFilters(filters = TestClustersThreadFilter.class)
4852
public class MultiClustersIT extends ESRestTestCase {
@@ -159,6 +163,36 @@ private Map<String, Object> runEsql(RestEsqlTestCase.RequestObjectBuilder reques
159163
}
160164
}
161165

166+
private <C, V> void assertResultMapForLike(
167+
boolean includeCCSMetadata,
168+
Map<String, Object> result,
169+
C columns,
170+
V values,
171+
boolean remoteOnly,
172+
boolean requireLikeListCapability
173+
) throws IOException {
174+
List<String> requiredCapabilities = new ArrayList<>(List.of("like_on_index_fields"));
175+
if (requireLikeListCapability) {
176+
requiredCapabilities.add("like_list_on_index_fields");
177+
}
178+
// the feature is completely supported if both local and remote clusters support it
179+
boolean isSupported = clusterHasCapability("POST", "/_query", List.of(), requiredCapabilities).orElse(false);
180+
try (RestClient remoteClient = remoteClusterClient()) {
181+
isSupported = isSupported
182+
&& clusterHasCapability(remoteClient, "POST", "/_query", List.of(), requiredCapabilities).orElse(false);
183+
}
184+
185+
if (isSupported) {
186+
assertResultMap(includeCCSMetadata, result, columns, values, remoteOnly);
187+
} else {
188+
logger.info("--> skipping data check for like index test, cluster does not support like index feature");
189+
// just verify that we did not get a partial result
190+
var clusters = result.get("_clusters");
191+
var reason = "unexpected partial results" + (clusters != null ? ": _clusters=" + clusters : "");
192+
assertThat(reason, result.get("is_partial"), anyOf(nullValue(), is(false)));
193+
}
194+
}
195+
162196
private <C, V> void assertResultMap(boolean includeCCSMetadata, Map<String, Object> result, C columns, V values, boolean remoteOnly) {
163197
MapMatcher mapMatcher = getResultMatcher(
164198
ccsMetadataAvailable(),
@@ -385,7 +419,7 @@ public void testLikeIndex() throws Exception {
385419
var values = List.of(List.of(remoteDocs.size(), REMOTE_CLUSTER_NAME + ":" + remoteIndex));
386420
String resultString = Strings.toString(JsonXContent.contentBuilder().prettyPrint().map(result));
387421
System.out.println(resultString);
388-
assertResultMap(includeCCSMetadata, result, columns, values, false);
422+
assertResultMapForLike(includeCCSMetadata, result, columns, values, false, false);
389423
}
390424

391425
public void testNotLikeIndex() throws Exception {
@@ -400,7 +434,7 @@ public void testNotLikeIndex() throws Exception {
400434
var values = List.of(List.of(localDocs.size(), localIndex));
401435
String resultString = Strings.toString(JsonXContent.contentBuilder().prettyPrint().map(result));
402436
System.out.println(resultString);
403-
assertResultMap(includeCCSMetadata, result, columns, values, false);
437+
assertResultMapForLike(includeCCSMetadata, result, columns, values, false, false);
404438
}
405439

406440
public void testLikeListIndex() throws Exception {
@@ -415,7 +449,7 @@ public void testLikeListIndex() throws Exception {
415449
var values = List.of(List.of(remoteDocs.size(), REMOTE_CLUSTER_NAME + ":" + remoteIndex));
416450
String resultString = Strings.toString(JsonXContent.contentBuilder().prettyPrint().map(result));
417451
System.out.println(resultString);
418-
assertResultMap(includeCCSMetadata, result, columns, values, false);
452+
assertResultMapForLike(includeCCSMetadata, result, columns, values, false, true);
419453
}
420454

421455
public void testNotLikeListIndex() throws Exception {
@@ -430,7 +464,7 @@ public void testNotLikeListIndex() throws Exception {
430464
var values = List.of(List.of(localDocs.size(), localIndex));
431465
String resultString = Strings.toString(JsonXContent.contentBuilder().prettyPrint().map(result));
432466
System.out.println(resultString);
433-
assertResultMap(includeCCSMetadata, result, columns, values, false);
467+
assertResultMapForLike(includeCCSMetadata, result, columns, values, false, true);
434468
}
435469

436470
public void testRLikeIndex() throws Exception {
@@ -443,8 +477,7 @@ public void testRLikeIndex() throws Exception {
443477
""", includeCCSMetadata);
444478
var columns = List.of(Map.of("name", "c", "type", "long"), Map.of("name", "_index", "type", "keyword"));
445479
var values = List.of(List.of(remoteDocs.size(), REMOTE_CLUSTER_NAME + ":" + remoteIndex));
446-
447-
assertResultMap(includeCCSMetadata, result, columns, values, false);
480+
assertResultMapForLike(includeCCSMetadata, result, columns, values, false, false);
448481
}
449482

450483
public void testNotRLikeIndex() throws Exception {
@@ -457,8 +490,7 @@ public void testNotRLikeIndex() throws Exception {
457490
""", includeCCSMetadata);
458491
var columns = List.of(Map.of("name", "c", "type", "long"), Map.of("name", "_index", "type", "keyword"));
459492
var values = List.of(List.of(localDocs.size(), localIndex));
460-
461-
assertResultMap(includeCCSMetadata, result, columns, values, false);
493+
assertResultMapForLike(includeCCSMetadata, result, columns, values, false, false);
462494
}
463495

464496
private RestClient remoteClusterClient() throws IOException {

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

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1215,7 +1215,11 @@ public enum Cap {
12151215
/**
12161216
* (Re)Added EXPLAIN command
12171217
*/
1218-
EXPLAIN(Build.current().isSnapshot());
1218+
EXPLAIN(Build.current().isSnapshot()),
1219+
/**
1220+
* Support improved behavior for LIKE operator when used with index fields.
1221+
*/
1222+
LIKE_ON_INDEX_FIELDS;
12191223

12201224
private final boolean enabled;
12211225

0 commit comments

Comments
 (0)