|
9 | 9 |
|
10 | 10 | package org.elasticsearch.search.suggest.phrase;
|
11 | 11 |
|
| 12 | +import org.elasticsearch.action.search.SearchPhaseExecutionException; |
12 | 13 | import org.elasticsearch.action.search.SearchRequestBuilder;
|
13 | 14 | import org.elasticsearch.action.search.ShardSearchFailure;
|
14 | 15 | import org.elasticsearch.common.settings.Settings;
|
@@ -49,15 +50,25 @@ public void testPhraseSuggestionWithNgramOnlyAnalyzerThrowsException() throws IO
|
49 | 50 | // 4. NoisyChannelSpellChecker.end() throws IllegalArgumentException
|
50 | 51 | SearchRequestBuilder searchBuilder = createSuggesterSearch("text.ngrams");
|
51 | 52 |
|
52 |
| - assertResponse(searchBuilder, response -> { |
53 |
| - assertThat(response.status(), equalTo(RestStatus.OK)); |
54 |
| - assertThat(response.getFailedShards(), greaterThan(0)); |
55 |
| - assertThat(response.getShardFailures().length, greaterThan(0)); |
56 |
| - for (ShardSearchFailure shardFailure : response.getShardFailures()) { |
57 |
| - assertTrue(shardFailure.getCause() instanceof IllegalArgumentException); |
58 |
| - assertEquals("At least one unigram is required but all tokens were ngrams", shardFailure.getCause().getMessage()); |
59 |
| - } |
60 |
| - }); |
| 53 | + try { |
| 54 | + assertResponse(searchBuilder, response -> { |
| 55 | + // We didn't fail all shards - we get a response with failed shards |
| 56 | + assertThat(response.status(), equalTo(RestStatus.OK)); |
| 57 | + assertThat(response.getFailedShards(), greaterThan(0)); |
| 58 | + assertThat(response.getShardFailures().length, greaterThan(0)); |
| 59 | + checkShardFailures(response.getShardFailures()); |
| 60 | + }); |
| 61 | + } catch (SearchPhaseExecutionException e) { |
| 62 | + // If all shards fail, we get a SearchPhaseExecutionException |
| 63 | + checkShardFailures(e.shardFailures()); |
| 64 | + } |
| 65 | + } |
| 66 | + |
| 67 | + private static void checkShardFailures(ShardSearchFailure[] shardFailures) { |
| 68 | + for (ShardSearchFailure shardFailure : shardFailures) { |
| 69 | + assertTrue(shardFailure.getCause() instanceof IllegalArgumentException); |
| 70 | + assertEquals("At least one unigram is required but all tokens were ngrams", shardFailure.getCause().getMessage()); |
| 71 | + } |
61 | 72 | }
|
62 | 73 |
|
63 | 74 | private static SearchRequestBuilder createSuggesterSearch(String fieldName) {
|
@@ -104,7 +115,7 @@ private void createIndexAndDocs(boolean outputUnigrams) throws IOException {
|
104 | 115 | assertAcked(
|
105 | 116 | prepareCreate("test").setSettings(
|
106 | 117 | Settings.builder()
|
107 |
| - .put(SETTING_NUMBER_OF_SHARDS, randomIntBetween(1, 5)) |
| 118 | + .put(SETTING_NUMBER_OF_SHARDS, randomIntBetween(1, 10)) |
108 | 119 | .put("index.analysis.analyzer.ngram_only.tokenizer", "standard")
|
109 | 120 | .putList("index.analysis.analyzer.ngram_only.filter", "my_shingle", "lowercase")
|
110 | 121 | .put("index.analysis.filter.my_shingle.type", "shingle")
|
|
0 commit comments