|
26 | 26 | import org.elasticsearch.action.search.SearchPhaseExecutionException;
|
27 | 27 | import org.elasticsearch.action.search.SearchResponse;
|
28 | 28 | import org.elasticsearch.cluster.health.ClusterHealthStatus;
|
| 29 | +import org.elasticsearch.common.settings.Settings; |
29 | 30 | import org.elasticsearch.common.xcontent.XContentBuilder;
|
30 | 31 | import org.elasticsearch.common.xcontent.XContentType;
|
31 | 32 | import org.elasticsearch.index.IndexSettings;
|
@@ -386,6 +387,9 @@ public void testNestedDefinedAsObject() throws Exception {
|
386 | 387 |
|
387 | 388 | public void testInnerHitsWithObjectFieldThatHasANestedField() throws Exception {
|
388 | 389 | assertAcked(prepareCreate("articles")
|
| 390 | + // number_of_shards = 1, because then we catch the expected exception in the same way. |
| 391 | + // (See expectThrows(...) below) |
| 392 | + .setSettings(Settings.builder().put("index.number_of_shards", 1)) |
389 | 393 | .addMapping("article", jsonBuilder().startObject()
|
390 | 394 | .startObject("properties")
|
391 | 395 | .startObject("comments")
|
@@ -418,18 +422,18 @@ public void testInnerHitsWithObjectFieldThatHasANestedField() throws Exception {
|
418 | 422 | .endObject()));
|
419 | 423 | indexRandom(true, requests);
|
420 | 424 |
|
421 |
| - SearchResponse response = client().prepareSearch("articles").setQuery(nestedQuery("comments.messages", |
422 |
| - matchQuery("comments.messages.message", "fox"), ScoreMode.Avg).innerHit(new InnerHitBuilder())).get(); |
| 425 | + Exception e = expectThrows(Exception.class, () -> client().prepareSearch("articles").setQuery(nestedQuery("comments.messages", |
| 426 | + matchQuery("comments.messages.message", "fox"), ScoreMode.Avg).innerHit(new InnerHitBuilder())).get()); |
423 | 427 | assertEquals("Cannot execute inner hits. One or more parent object fields of nested field [comments.messages] are " +
|
424 |
| - "not nested. All parent fields need to be nested fields too", response.getShardFailures()[0].getCause().getMessage()); |
| 428 | + "not nested. All parent fields need to be nested fields too", e.getCause().getCause().getMessage()); |
425 | 429 |
|
426 |
| - response = client().prepareSearch("articles").setQuery(nestedQuery("comments.messages", |
| 430 | + e = expectThrows(Exception.class, () -> client().prepareSearch("articles").setQuery(nestedQuery("comments.messages", |
427 | 431 | matchQuery("comments.messages.message", "fox"), ScoreMode.Avg).innerHit(new InnerHitBuilder()
|
428 |
| - .setFetchSourceContext(new FetchSourceContext(true)))).get(); |
| 432 | + .setFetchSourceContext(new FetchSourceContext(true)))).get()); |
429 | 433 | assertEquals("Cannot execute inner hits. One or more parent object fields of nested field [comments.messages] are " +
|
430 |
| - "not nested. All parent fields need to be nested fields too", response.getShardFailures()[0].getCause().getMessage()); |
| 434 | + "not nested. All parent fields need to be nested fields too", e.getCause().getCause().getMessage()); |
431 | 435 |
|
432 |
| - response = client().prepareSearch("articles") |
| 436 | + SearchResponse response = client().prepareSearch("articles") |
433 | 437 | .setQuery(nestedQuery("comments.messages", matchQuery("comments.messages.message", "fox"), ScoreMode.Avg)
|
434 | 438 | .innerHit(new InnerHitBuilder().setFetchSourceContext(new FetchSourceContext(false)))).get();
|
435 | 439 | assertNoFailures(response);
|
|
0 commit comments