Skip to content

Commit 829fb56

Browse files
authored
Fix PhraseSuggesterIT test when all shards fail (#132350)
1 parent 2559e28 commit 829fb56

File tree

2 files changed

+21
-13
lines changed

2 files changed

+21
-13
lines changed

muted-tests.yml

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -533,9 +533,6 @@ tests:
533533
- class: org.elasticsearch.xpack.logsdb.qa.LogsDbVersusReindexedLogsDbChallengeRestIT
534534
method: testTermsQuery
535535
issue: https://github.com/elastic/elasticsearch/issues/132337
536-
- class: org.elasticsearch.search.suggest.phrase.PhraseSuggesterIT
537-
method: testPhraseSuggestionWithNgramOnlyAnalyzerThrowsException
538-
issue: https://github.com/elastic/elasticsearch/issues/132347
539536
- class: org.elasticsearch.xpack.esql.action.CrossClusterAsyncQueryIT
540537
method: testBadAsyncId
541538
issue: https://github.com/elastic/elasticsearch/issues/132353

server/src/internalClusterTest/java/org/elasticsearch/search/suggest/phrase/PhraseSuggesterIT.java

Lines changed: 21 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99

1010
package org.elasticsearch.search.suggest.phrase;
1111

12+
import org.elasticsearch.action.search.SearchPhaseExecutionException;
1213
import org.elasticsearch.action.search.SearchRequestBuilder;
1314
import org.elasticsearch.action.search.ShardSearchFailure;
1415
import org.elasticsearch.common.settings.Settings;
@@ -49,15 +50,25 @@ public void testPhraseSuggestionWithNgramOnlyAnalyzerThrowsException() throws IO
4950
// 4. NoisyChannelSpellChecker.end() throws IllegalArgumentException
5051
SearchRequestBuilder searchBuilder = createSuggesterSearch("text.ngrams");
5152

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+
}
6172
}
6273

6374
private static SearchRequestBuilder createSuggesterSearch(String fieldName) {
@@ -104,7 +115,7 @@ private void createIndexAndDocs(boolean outputUnigrams) throws IOException {
104115
assertAcked(
105116
prepareCreate("test").setSettings(
106117
Settings.builder()
107-
.put(SETTING_NUMBER_OF_SHARDS, randomIntBetween(1, 5))
118+
.put(SETTING_NUMBER_OF_SHARDS, randomIntBetween(1, 10))
108119
.put("index.analysis.analyzer.ngram_only.tokenizer", "standard")
109120
.putList("index.analysis.analyzer.ngram_only.filter", "my_shingle", "lowercase")
110121
.put("index.analysis.filter.my_shingle.type", "shingle")

0 commit comments

Comments
 (0)