Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 0 additions & 3 deletions muted-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -533,9 +533,6 @@ tests:
- class: org.elasticsearch.xpack.logsdb.qa.LogsDbVersusReindexedLogsDbChallengeRestIT
method: testTermsQuery
issue: https://github.com/elastic/elasticsearch/issues/132337
- class: org.elasticsearch.search.suggest.phrase.PhraseSuggesterIT
method: testPhraseSuggestionWithNgramOnlyAnalyzerThrowsException
issue: https://github.com/elastic/elasticsearch/issues/132347
- class: org.elasticsearch.xpack.esql.action.CrossClusterAsyncQueryIT
method: testBadAsyncId
issue: https://github.com/elastic/elasticsearch/issues/132353
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

package org.elasticsearch.search.suggest.phrase;

import org.elasticsearch.action.search.SearchPhaseExecutionException;
import org.elasticsearch.action.search.SearchRequestBuilder;
import org.elasticsearch.action.search.ShardSearchFailure;
import org.elasticsearch.common.settings.Settings;
Expand Down Expand Up @@ -49,15 +50,25 @@ public void testPhraseSuggestionWithNgramOnlyAnalyzerThrowsException() throws IO
// 4. NoisyChannelSpellChecker.end() throws IllegalArgumentException
SearchRequestBuilder searchBuilder = createSuggesterSearch("text.ngrams");

assertResponse(searchBuilder, response -> {
assertThat(response.status(), equalTo(RestStatus.OK));
assertThat(response.getFailedShards(), greaterThan(0));
assertThat(response.getShardFailures().length, greaterThan(0));
for (ShardSearchFailure shardFailure : response.getShardFailures()) {
assertTrue(shardFailure.getCause() instanceof IllegalArgumentException);
assertEquals("At least one unigram is required but all tokens were ngrams", shardFailure.getCause().getMessage());
}
});
try {
assertResponse(searchBuilder, response -> {
// We didn't fail all shards - we get a response with failed shards
assertThat(response.status(), equalTo(RestStatus.OK));
assertThat(response.getFailedShards(), greaterThan(0));
assertThat(response.getShardFailures().length, greaterThan(0));
checkShardFailures(response.getShardFailures());
});
} catch (SearchPhaseExecutionException e) {
// If all shards fail, we get a SearchPhaseExecutionException
checkShardFailures(e.shardFailures());
}
}

private static void checkShardFailures(ShardSearchFailure[] shardFailures) {
for (ShardSearchFailure shardFailure : shardFailures) {
assertTrue(shardFailure.getCause() instanceof IllegalArgumentException);
assertEquals("At least one unigram is required but all tokens were ngrams", shardFailure.getCause().getMessage());
}
}

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