diff --git a/backend/elasticsearch/src/main/java/org/hibernate/search/backend/elasticsearch/impl/ElasticsearchBackendImpl.java b/backend/elasticsearch/src/main/java/org/hibernate/search/backend/elasticsearch/impl/ElasticsearchBackendImpl.java index 3a49dcfc997..90722be6698 100644 --- a/backend/elasticsearch/src/main/java/org/hibernate/search/backend/elasticsearch/impl/ElasticsearchBackendImpl.java +++ b/backend/elasticsearch/src/main/java/org/hibernate/search/backend/elasticsearch/impl/ElasticsearchBackendImpl.java @@ -310,10 +310,10 @@ private IndexSettings customIndexSettings(BackendBuildContext buildContext, } } catch (IOException e) { - throw log.customIndexSettingsErrorOnLoading( filePath, e, indexEventContext ); + throw log.customIndexSettingsErrorOnLoading( filePath, e.getMessage(), e, indexEventContext ); } catch (JsonSyntaxException e) { - throw log.customIndexSettingsJsonSyntaxErrors( filePath, e, indexEventContext ); + throw log.customIndexSettingsJsonSyntaxErrors( filePath, e.getMessage(), e, indexEventContext ); } } @@ -335,10 +335,10 @@ private RootTypeMapping customIndexMappings(BackendBuildContext buildContext, } } catch (IOException e) { - throw log.customIndexMappingErrorOnLoading( filePath, e, indexEventContext ); + throw log.customIndexMappingErrorOnLoading( filePath, e.getMessage(), e, indexEventContext ); } catch (JsonSyntaxException e) { - throw log.customIndexMappingJsonSyntaxErrors( filePath, e, indexEventContext ); + throw log.customIndexMappingJsonSyntaxErrors( filePath, e.getMessage(), e, indexEventContext ); } } } diff --git a/backend/elasticsearch/src/main/java/org/hibernate/search/backend/elasticsearch/logging/impl/Log.java b/backend/elasticsearch/src/main/java/org/hibernate/search/backend/elasticsearch/logging/impl/Log.java index fe280aa59b2..d82ea514bca 100644 --- a/backend/elasticsearch/src/main/java/org/hibernate/search/backend/elasticsearch/logging/impl/Log.java +++ b/backend/elasticsearch/src/main/java/org/hibernate/search/backend/elasticsearch/logging/impl/Log.java @@ -645,12 +645,12 @@ SearchException differentImplementationClassForQueryElement(@FormatWith(ClassFor @Message(id = ID_OFFSET + 131, value = "Unable to find the given custom index settings file: '%1$s'.") SearchException customIndexSettingsFileNotFound(String filePath, @Param EventContext context); - @Message(id = ID_OFFSET + 132, value = "Error on loading the given custom index settings file: '%1$s'.") - SearchException customIndexSettingsErrorOnLoading(String filePath, @Cause Exception cause, + @Message(id = ID_OFFSET + 132, value = "Error on loading the given custom index settings file '%1$s': %2$s") + SearchException customIndexSettingsErrorOnLoading(String filePath, String causeMessage, @Cause Exception cause, @Param EventContext context); - @Message(id = ID_OFFSET + 133, value = "There are some JSON syntax errors on the given custom index settings file: '%1$s'.") - SearchException customIndexSettingsJsonSyntaxErrors(String filePath, @Cause Exception cause, + @Message(id = ID_OFFSET + 133, value = "There are some JSON syntax errors on the given custom index settings file '%1$s': %2$s") + SearchException customIndexSettingsJsonSyntaxErrors(String filePath, String causeMessage, @Cause Exception cause, @Param EventContext context); @Message(id = ID_OFFSET + 134, value = "Invalid use of 'missing().first()' for an ascending distance sort. Elasticsearch always assumes missing values have a distance of '+Infinity', and this behavior cannot be customized.") @@ -701,12 +701,12 @@ SearchException incompatibleElasticsearchVersionOnStart(ElasticsearchVersion ver @Message(id = ID_OFFSET + 151, value = "Unable to find the given custom index mapping file: '%1$s'.") SearchException customIndexMappingFileNotFound(String filePath, @Param EventContext context); - @Message(id = ID_OFFSET + 152, value = "Error on loading the given custom index mapping file: '%1$s'.") - SearchException customIndexMappingErrorOnLoading(String filePath, @Cause Exception cause, + @Message(id = ID_OFFSET + 152, value = "Error on loading the given custom index mapping file '%1$s': %2$s") + SearchException customIndexMappingErrorOnLoading(String filePath, String causeMessage, @Cause Exception cause, @Param EventContext context); - @Message(id = ID_OFFSET + 153, value = "There are some JSON syntax errors on the given custom index mapping file: '%1$s'.") - SearchException customIndexMappingJsonSyntaxErrors(String filePath, @Cause Exception cause, + @Message(id = ID_OFFSET + 153, value = "There are some JSON syntax errors on the given custom index mapping file '%1$s': %2$s") + SearchException customIndexMappingJsonSyntaxErrors(String filePath, String causeMessage, @Cause Exception cause, @Param EventContext context); } diff --git a/integrationtest/backend/elasticsearch/src/test/java/org/hibernate/search/integrationtest/backend/elasticsearch/schema/custom/ElasticsearchCustomIndexMappingIT.java b/integrationtest/backend/elasticsearch/src/test/java/org/hibernate/search/integrationtest/backend/elasticsearch/schema/custom/ElasticsearchCustomIndexMappingIT.java new file mode 100644 index 00000000000..57db077d3dd --- /dev/null +++ b/integrationtest/backend/elasticsearch/src/test/java/org/hibernate/search/integrationtest/backend/elasticsearch/schema/custom/ElasticsearchCustomIndexMappingIT.java @@ -0,0 +1,80 @@ +/* + * Hibernate Search, full-text search for your domain model + * + * License: GNU Lesser General Public License (LGPL), version 2.1 or later + * See the lgpl.txt file in the root directory or . + */ +package org.hibernate.search.integrationtest.backend.elasticsearch.schema.custom; + +import static org.assertj.core.api.Assertions.assertThatThrownBy; + +import org.hibernate.search.backend.elasticsearch.cfg.ElasticsearchIndexSettings; +import org.hibernate.search.engine.backend.document.IndexFieldReference; +import org.hibernate.search.engine.backend.document.model.dsl.IndexSchemaElement; +import org.hibernate.search.integrationtest.backend.tck.testsupport.util.rule.SearchSetupHelper; +import org.hibernate.search.util.common.SearchException; +import org.hibernate.search.util.impl.integrationtest.mapper.stub.SimpleMappedIndex; +import org.hibernate.search.util.impl.test.annotation.TestForIssue; + +import org.junit.Rule; +import org.junit.Test; + +public class ElasticsearchCustomIndexMappingIT { + + @Rule + public final SearchSetupHelper setupHelper = new SearchSetupHelper(); + + private final SimpleMappedIndex index = SimpleMappedIndex.of( IndexBinding::new ); + + // Valid cases are tested elsewhere, e.g. ElasticsearchIndexSchemaManagerCreationCustomMappingIT + + @Test + public void notExisting() { + assertThatThrownBy( () -> setupHelper.start().withIndex( index ) + .withIndexProperty( index.name(), ElasticsearchIndexSettings.SCHEMA_MANAGEMENT_MAPPING_FILE, + "custom-index-mapping/not-existing.json" + ).setup() ) + .isInstanceOf( SearchException.class ) + .hasMessageContainingAll( + "Unable to find the given custom index mapping file:", + "custom-index-mapping/not-existing.json" + ); + } + + @Test + @TestForIssue(jiraKey = "HSEARCH-4438") + public void notParsable() { + assertThatThrownBy( () -> setupHelper.start().withIndex( index ) + .withIndexProperty( index.name(), ElasticsearchIndexSettings.SCHEMA_MANAGEMENT_MAPPING_FILE, + "custom-index-mapping/not-parsable.json" + ).setup() ) + .isInstanceOf( SearchException.class ) + .hasMessageContainingAll( + "There are some JSON syntax errors on the given custom index mapping file", + "custom-index-mapping/not-parsable.json", + "Expected BEGIN_OBJECT but was STRING at line 1 column 1" + ); + } + + @Test + public void unknownParameter() { + assertThatThrownBy( () -> setupHelper.start().withIndex( index ) + .withIndexProperty( index.name(), ElasticsearchIndexSettings.SCHEMA_MANAGEMENT_MAPPING_FILE, + "custom-index-mapping/unknown-parameter.json" + ).setup() ) + .isInstanceOf( SearchException.class ) + .hasMessageContainingAll( + "Hibernate Search encountered failures during bootstrap", + "Elasticsearch response indicates a failure", + "mapper_parsing_exception", "unknown parameter", "someUnknownParameter" + ); + } + + private static class IndexBinding { + final IndexFieldReference string; + + IndexBinding(IndexSchemaElement root) { + string = root.field( "string", f -> f.asString() ).toReference(); + } + } +} diff --git a/integrationtest/backend/elasticsearch/src/test/java/org/hibernate/search/integrationtest/backend/elasticsearch/schema/custom/ElasticsearchCustomIndexSettingsIT.java b/integrationtest/backend/elasticsearch/src/test/java/org/hibernate/search/integrationtest/backend/elasticsearch/schema/custom/ElasticsearchCustomIndexSettingsIT.java index 3c9402e25a3..4384295976a 100644 --- a/integrationtest/backend/elasticsearch/src/test/java/org/hibernate/search/integrationtest/backend/elasticsearch/schema/custom/ElasticsearchCustomIndexSettingsIT.java +++ b/integrationtest/backend/elasticsearch/src/test/java/org/hibernate/search/integrationtest/backend/elasticsearch/schema/custom/ElasticsearchCustomIndexSettingsIT.java @@ -19,6 +19,7 @@ import org.hibernate.search.integrationtest.backend.tck.testsupport.util.rule.SearchSetupHelper; import org.hibernate.search.util.common.SearchException; import org.hibernate.search.util.impl.integrationtest.mapper.stub.SimpleMappedIndex; +import org.hibernate.search.util.impl.test.annotation.TestForIssue; import org.junit.Rule; import org.junit.Test; @@ -59,6 +60,7 @@ public void notExisting() { } @Test + @TestForIssue(jiraKey = "HSEARCH-4438") public void notParsable() { assertThatThrownBy( () -> setupHelper.start().withIndex( index ) .withIndexProperty( index.name(), ElasticsearchIndexSettings.SCHEMA_MANAGEMENT_SETTINGS_FILE, @@ -66,8 +68,9 @@ public void notParsable() { ).setup() ) .isInstanceOf( SearchException.class ) .hasMessageContainingAll( - "There are some JSON syntax errors on the given custom index settings file:", - "custom-index-settings/not-parsable.json" + "There are some JSON syntax errors on the given custom index settings file", + "custom-index-settings/not-parsable.json", + "Expected BEGIN_OBJECT but was STRING at line 1 column 1" ); } diff --git a/integrationtest/backend/elasticsearch/src/test/resources/custom-index-mapping/not-parsable.json b/integrationtest/backend/elasticsearch/src/test/resources/custom-index-mapping/not-parsable.json new file mode 100644 index 00000000000..198da49d8db --- /dev/null +++ b/integrationtest/backend/elasticsearch/src/test/resources/custom-index-mapping/not-parsable.json @@ -0,0 +1 @@ +--- NOT PARSABLE JSON -- \ No newline at end of file diff --git a/integrationtest/backend/elasticsearch/src/test/resources/custom-index-mapping/unknown-parameter.json b/integrationtest/backend/elasticsearch/src/test/resources/custom-index-mapping/unknown-parameter.json new file mode 100644 index 00000000000..6183487e8a6 --- /dev/null +++ b/integrationtest/backend/elasticsearch/src/test/resources/custom-index-mapping/unknown-parameter.json @@ -0,0 +1,8 @@ +{ + "properties":{ + "userField":{ + "type":"keyword", + "someUnknownParameter":true + } + } +} \ No newline at end of file