From c918a50109e1a3d20e928f7936f3f0dcdbca81c4 Mon Sep 17 00:00:00 2001 From: Benjamin Trent <4357155+benwtrent@users.noreply.github.com> Date: Fri, 28 Feb 2025 12:59:32 -0500 Subject: [PATCH 1/5] Adjust exception thrown when unable to load hunspell dict --- .../test/indices.create/10_basic.yml | 27 +++++++++++++++++++ .../indices/analysis/HunspellService.java | 2 +- .../indices/CreateIndexCapabilities.java | 5 +++- 3 files changed, 32 insertions(+), 2 deletions(-) diff --git a/rest-api-spec/src/yamlRestTest/resources/rest-api-spec/test/indices.create/10_basic.yml b/rest-api-spec/src/yamlRestTest/resources/rest-api-spec/test/indices.create/10_basic.yml index 7fe95aa4f4ff1..dc5fcf1596e89 100644 --- a/rest-api-spec/src/yamlRestTest/resources/rest-api-spec/test/indices.create/10_basic.yml +++ b/rest-api-spec/src/yamlRestTest/resources/rest-api-spec/test/indices.create/10_basic.yml @@ -273,3 +273,30 @@ - match: { error.type: "mapper_parsing_exception" } - match: { error.reason: "Failed to parse mapping: The mapper type [invalid] declared on field [raw] does not exist. It might have been created within a future version or requires a plugin to be installed. Check the documentation." } +--- +"Create index with hunspell missing dict": + - requires: + test_runner_features: [ capabilities ] + capabilities: + - method: PUT + path: /{index} + capabilities: [ hunspell_dict_400 ] + reason: "bugfix 'hunspell_dict_400' capability required" + + - do: + catch: bad_request + indices.create: + index: bad_hunspell_index + body: + settings: + analysis: + analyzer: + en: + tokenizer: standard + filter: + - my_en_US_dict_stemmer + filter: + my_en_US_dict_stemmer: + type: hunspell + locale: en_US + dedup: false diff --git a/server/src/main/java/org/elasticsearch/indices/analysis/HunspellService.java b/server/src/main/java/org/elasticsearch/indices/analysis/HunspellService.java index bfe1cd9b28de1..ab6e20c39f720 100644 --- a/server/src/main/java/org/elasticsearch/indices/analysis/HunspellService.java +++ b/server/src/main/java/org/elasticsearch/indices/analysis/HunspellService.java @@ -99,7 +99,7 @@ public HunspellService(final Settings settings, final Environment env, final Map try { return loadDictionary(locale, settings, env); } catch (Exception e) { - throw new IllegalStateException("failed to load hunspell dictionary for locale: " + locale, e); + throw new IllegalArgumentException("failed to load hunspell dictionary for locale: " + locale, e); } }; if (HUNSPELL_LAZY_LOAD.get(settings) == false) { diff --git a/server/src/main/java/org/elasticsearch/rest/action/admin/indices/CreateIndexCapabilities.java b/server/src/main/java/org/elasticsearch/rest/action/admin/indices/CreateIndexCapabilities.java index 334e68648d853..928c872b6ad71 100644 --- a/server/src/main/java/org/elasticsearch/rest/action/admin/indices/CreateIndexCapabilities.java +++ b/server/src/main/java/org/elasticsearch/rest/action/admin/indices/CreateIndexCapabilities.java @@ -28,9 +28,12 @@ public class CreateIndexCapabilities { private static final String NESTED_DENSE_VECTOR_SYNTHETIC_TEST = "nested_dense_vector_synthetic_test"; + private static final String HUNSPELL_DICT_400 = "hunspell_dict_400"; + public static final Set CAPABILITIES = Set.of( LOGSDB_INDEX_MODE_CAPABILITY, LOOKUP_INDEX_MODE_CAPABILITY, - NESTED_DENSE_VECTOR_SYNTHETIC_TEST + NESTED_DENSE_VECTOR_SYNTHETIC_TEST, + HUNSPELL_DICT_400 ); } From 9152b07e3c0b3638d51952535d0b72f3fb116888 Mon Sep 17 00:00:00 2001 From: Benjamin Trent Date: Fri, 28 Feb 2025 13:02:16 -0500 Subject: [PATCH 2/5] Update docs/changelog/123743.yaml --- docs/changelog/123743.yaml | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 docs/changelog/123743.yaml diff --git a/docs/changelog/123743.yaml b/docs/changelog/123743.yaml new file mode 100644 index 0000000000000..50fccfd6030ae --- /dev/null +++ b/docs/changelog/123743.yaml @@ -0,0 +1,5 @@ +pr: 123743 +summary: Adjust exception thrown when unable to load hunspell dict +area: Analysis +type: bug +issues: [] From 52bec806ce38c8a89e797935c4ac846dac971db6 Mon Sep 17 00:00:00 2001 From: Benjamin Trent <4357155+benwtrent@users.noreply.github.com> Date: Fri, 28 Feb 2025 14:36:16 -0500 Subject: [PATCH 3/5] fixing tests --- .../rest-api-spec/test/indices.analyze/15_analyze.yml | 4 ---- .../elasticsearch/indices/analyze/HunspellServiceTests.java | 4 ++-- 2 files changed, 2 insertions(+), 6 deletions(-) diff --git a/modules/analysis-common/src/yamlRestTest/resources/rest-api-spec/test/indices.analyze/15_analyze.yml b/modules/analysis-common/src/yamlRestTest/resources/rest-api-spec/test/indices.analyze/15_analyze.yml index 24e04174cd1e4..059d264e7b9d6 100644 --- a/modules/analysis-common/src/yamlRestTest/resources/rest-api-spec/test/indices.analyze/15_analyze.yml +++ b/modules/analysis-common/src/yamlRestTest/resources/rest-api-spec/test/indices.analyze/15_analyze.yml @@ -80,7 +80,3 @@ filter: type: hunspell locale: en_US - - - match: { status: 400 } - - match: { error.type: illegal_argument_exception } - - match: { error.reason: "Can not build a custom analyzer" } diff --git a/server/src/test/java/org/elasticsearch/indices/analyze/HunspellServiceTests.java b/server/src/test/java/org/elasticsearch/indices/analyze/HunspellServiceTests.java index 1a27954eed98b..8530fd21ea77d 100644 --- a/server/src/test/java/org/elasticsearch/indices/analyze/HunspellServiceTests.java +++ b/server/src/test/java/org/elasticsearch/indices/analyze/HunspellServiceTests.java @@ -64,7 +64,7 @@ public void testDicWithNoAff() throws Exception { .put(Environment.PATH_HOME_SETTING.getKey(), createTempDir()) .build(); - IllegalStateException e = expectThrows(IllegalStateException.class, () -> { + IllegalArgumentException e = expectThrows(IllegalArgumentException.class, () -> { final Environment environment = new Environment(settings, getDataPath("/indices/analyze/no_aff_conf_dir")); new HunspellService(settings, environment, emptyMap()).getDictionary("en_US"); }); @@ -78,7 +78,7 @@ public void testDicWithTwoAffs() throws Exception { .put(Environment.PATH_HOME_SETTING.getKey(), createTempDir()) .build(); - IllegalStateException e = expectThrows(IllegalStateException.class, () -> { + IllegalArgumentException e = expectThrows(IllegalArgumentException.class, () -> { final Environment environment = new Environment(settings, getDataPath("/indices/analyze/two_aff_conf_dir")); new HunspellService(settings, environment, emptyMap()).getDictionary("en_US"); }); From 50c2342180545752349e1c998da906d75731d295 Mon Sep 17 00:00:00 2001 From: Benjamin Trent <4357155+benwtrent@users.noreply.github.com> Date: Fri, 28 Feb 2025 15:09:13 -0500 Subject: [PATCH 4/5] fix tests --- .../rest-api-spec/test/indices.analyze/15_analyze.yml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/modules/analysis-common/src/yamlRestTest/resources/rest-api-spec/test/indices.analyze/15_analyze.yml b/modules/analysis-common/src/yamlRestTest/resources/rest-api-spec/test/indices.analyze/15_analyze.yml index 059d264e7b9d6..72d74fa51d6af 100644 --- a/modules/analysis-common/src/yamlRestTest/resources/rest-api-spec/test/indices.analyze/15_analyze.yml +++ b/modules/analysis-common/src/yamlRestTest/resources/rest-api-spec/test/indices.analyze/15_analyze.yml @@ -64,11 +64,11 @@ "Custom analyzer is not buildable": - requires: test_runner_features: [ capabilities ] - reason: This capability required to run test capabilities: - - method: GET - path: /_analyze - capabilities: [ wrong_custom_analyzer_returns_400 ] + - method: PUT + path: /{index} + capabilities: [ hunspell_dict_400 ] + reason: "bugfix 'hunspell_dict_400' capability required" - do: catch: bad_request From 05110aab0e7206895d244403b7cac36c2e50eceb Mon Sep 17 00:00:00 2001 From: Benjamin Trent <4357155+benwtrent@users.noreply.github.com> Date: Fri, 28 Feb 2025 15:46:30 -0500 Subject: [PATCH 5/5] skipping compat test --- modules/analysis-common/build.gradle | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/modules/analysis-common/build.gradle b/modules/analysis-common/build.gradle index 0c8821f29dbf1..a2d00b5276a02 100644 --- a/modules/analysis-common/build.gradle +++ b/modules/analysis-common/build.gradle @@ -6,8 +6,6 @@ * your election, the "Elastic License 2.0", the "GNU Affero General Public * License v3.0 only", or the "Server Side Public License, v 1". */ -import org.elasticsearch.gradle.Version - apply plugin: 'elasticsearch.internal-yaml-rest-test' apply plugin: 'elasticsearch.yaml-rest-compat-test' apply plugin: 'elasticsearch.internal-cluster-test' @@ -36,6 +34,7 @@ artifacts { tasks.named("yamlRestCompatTestTransform").configure { task -> task.replaceValueInMatch("tokens.0.token", "absenČ›", "romanian") + task.skipTest("indices.analyze/15_analyze/Custom analyzer is not buildable", "error response changed with #123743") } tasks.named("yamlRestTest").configure {