3030import org .junit .rules .TestRule ;
3131
3232import java .io .IOException ;
33+ import java .util .ArrayList ;
3334import java .util .List ;
3435import java .util .Map ;
3536import java .util .Set ;
4344import static org .hamcrest .Matchers .equalTo ;
4445import static org .hamcrest .Matchers .greaterThanOrEqualTo ;
4546import 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 )
4852public 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 {
0 commit comments