10
10
import org .elasticsearch .action .admin .indices .alias .IndicesAliasesRequest ;
11
11
import org .elasticsearch .action .admin .indices .alias .IndicesAliasesRequestBuilder ;
12
12
import org .elasticsearch .client .internal .Client ;
13
+ import org .elasticsearch .common .settings .Settings ;
13
14
import org .elasticsearch .xpack .core .enrich .EnrichPolicy ;
14
15
import org .elasticsearch .xpack .core .enrich .action .ExecuteEnrichPolicyAction ;
15
16
import org .elasticsearch .xpack .core .enrich .action .PutEnrichPolicyAction ;
@@ -374,7 +375,7 @@ public void testLookupJoinMissingKey() throws IOException {
374
375
);
375
376
assertThat (ex .getMessage (), containsString ("Unknown column [local_tag] in right side of join" ));
376
377
377
- // Add KEEP clause to try and trick the field-caps result parser
378
+ // Add KEEP clause to try and trick the field-caps result parser into returning empty mapping
378
379
ex = expectThrows (
379
380
VerificationException .class ,
380
381
() -> runQuery ("FROM logs-* | LOOKUP JOIN values_lookup ON v | KEEP v" , randomBoolean ())
@@ -385,22 +386,13 @@ public void testLookupJoinMissingKey() throws IOException {
385
386
VerificationException .class ,
386
387
() -> runQuery ("FROM logs-*,c*:logs-* | LOOKUP JOIN values_lookup ON v | KEEP v" , randomBoolean ())
387
388
);
388
- // FIXME: strictly speaking this message is not correct, as the index is available, but the field is not
389
- assertThat (ex .getMessage (), containsString ("lookup index [values_lookup] is not available" ));
390
-
391
- try (EsqlQueryResponse resp = runQuery ("FROM c*:logs-* | LOOKUP JOIN values_lookup ON v | KEEP v" , randomBoolean ())) {
392
- List <List <Object >> values = getValuesList (resp );
393
- assertThat (values , hasSize (0 ));
394
- EsqlExecutionInfo executionInfo = resp .getExecutionInfo ();
395
- assertThat (executionInfo .getClusters ().size (), equalTo (1 ));
396
- assertTrue (executionInfo .isPartial ());
389
+ assertThat (ex .getMessage (), containsString ("Unknown column [v] in right side of join" ));
397
390
398
- var remoteCluster = executionInfo .getCluster (REMOTE_CLUSTER_1 );
399
- assertThat (remoteCluster .getStatus (), equalTo (EsqlExecutionInfo .Cluster .Status .SKIPPED ));
400
- assertThat (remoteCluster .getFailures ().size (), equalTo (1 ));
401
- var failure = remoteCluster .getFailures ().get (0 );
402
- assertThat (failure .reason (), containsString ("lookup index [values_lookup] is not available in remote cluster [cluster-a]" ));
403
- }
391
+ ex = expectThrows (
392
+ VerificationException .class ,
393
+ () -> runQuery ("FROM c*:logs-* | LOOKUP JOIN values_lookup ON v | KEEP v" , randomBoolean ())
394
+ );
395
+ assertThat (ex .getMessage (), containsString ("Unknown column [v] in right side of join" ));
404
396
405
397
setSkipUnavailable (REMOTE_CLUSTER_1 , false );
406
398
try (
@@ -422,19 +414,40 @@ public void testLookupJoinMissingKey() throws IOException {
422
414
assertThat (remoteCluster .getStatus (), equalTo (EsqlExecutionInfo .Cluster .Status .SUCCESSFUL ));
423
415
}
424
416
425
- // Add KEEP clause to try and trick the field-caps result parser
417
+ // Add KEEP clause to try and trick the field-caps result parser into returning empty mapping
426
418
ex = expectThrows (
427
419
VerificationException .class ,
428
420
() -> runQuery ("FROM c*:logs-* | LOOKUP JOIN values_lookup ON v | KEEP v" , randomBoolean ())
429
421
);
430
- assertThat (ex .getMessage (), containsString ("lookup index [values_lookup] is not available in remote cluster [cluster-a] " ));
422
+ assertThat (ex .getMessage (), containsString ("Unknown column [v] in right side of join " ));
431
423
432
424
ex = expectThrows (
433
425
VerificationException .class ,
434
426
() -> runQuery ("FROM logs-*,c*:logs-* | LOOKUP JOIN values_lookup ON v | KEEP v" , randomBoolean ())
435
427
);
436
- assertThat (ex .getMessage (), containsString ("lookup index [values_lookup] is not available in remote cluster [cluster-a]" ));
428
+ assertThat (ex .getMessage (), containsString ("Unknown column [v] in right side of join" ));
429
+ }
430
+
431
+ public void testLookupJoinEmptyIndex () throws IOException {
432
+ setupClusters (2 );
433
+ populateEmptyIndices (LOCAL_CLUSTER , "values_lookup" );
434
+ populateEmptyIndices (REMOTE_CLUSTER_1 , "values_lookup" );
435
+
436
+ setSkipUnavailable (REMOTE_CLUSTER_1 , false );
437
437
438
+ Exception ex ;
439
+ for (String index : List .of ("values_lookup" , "values_lookup_map" , "values_lookup_map_lookup" )) {
440
+ ex = expectThrows (
441
+ VerificationException .class ,
442
+ () -> runQuery ("FROM logs-* | LOOKUP JOIN " + index + " ON v | KEEP v" , randomBoolean ())
443
+ );
444
+ assertThat (ex .getMessage (), containsString ("Unknown column [v] in right side of join" ));
445
+ ex = expectThrows (
446
+ VerificationException .class ,
447
+ () -> runQuery ("FROM c*:logs-* | LOOKUP JOIN " + index + " ON v | KEEP v" , randomBoolean ())
448
+ );
449
+ assertThat (ex .getMessage (), containsString ("Unknown column [v] in right side of join" ));
450
+ }
438
451
}
439
452
440
453
public void testLookupJoinIndexMode () throws IOException {
@@ -570,4 +583,23 @@ protected void setupAlias(String clusterAlias, String indexName, String aliasNam
570
583
assertAcked (client .admin ().indices ().aliases (indicesAliasesRequestBuilder .request ()));
571
584
}
572
585
586
+ protected void populateEmptyIndices (String clusterAlias , String indexName ) {
587
+ Client client = client (clusterAlias );
588
+ // Empty body
589
+ assertAcked (client .admin ().indices ().prepareCreate (indexName ));
590
+ client .admin ().indices ().prepareRefresh (indexName ).get ();
591
+ // mappings + settings
592
+ assertAcked (
593
+ client .admin ()
594
+ .indices ()
595
+ .prepareCreate (indexName + "_map_lookup" )
596
+ .setMapping ()
597
+ .setSettings (Settings .builder ().put ("index.mode" , "lookup" ))
598
+ );
599
+ client .admin ().indices ().prepareRefresh (indexName + "_map_lookup" ).get ();
600
+ // mappings only
601
+ assertAcked (client .admin ().indices ().prepareCreate (indexName + "_map" ).setMapping ());
602
+ client .admin ().indices ().prepareRefresh (indexName + "_map" ).get ();
603
+ }
604
+
573
605
}
0 commit comments