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
Original file line number Diff line number Diff line change
Expand Up @@ -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 );
}
}

Expand All @@ -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 );
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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.")
Expand Down Expand Up @@ -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);

}
Original file line number Diff line number Diff line change
@@ -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 <http://www.gnu.org/licenses/lgpl-2.1.html>.
*/
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<IndexBinding> 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> string;

IndexBinding(IndexSchemaElement root) {
string = root.field( "string", f -> f.asString() ).toReference();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -59,15 +60,17 @@ public void notExisting() {
}

@Test
@TestForIssue(jiraKey = "HSEARCH-4438")
public void notParsable() {
assertThatThrownBy( () -> setupHelper.start().withIndex( index )
.withIndexProperty( index.name(), ElasticsearchIndexSettings.SCHEMA_MANAGEMENT_SETTINGS_FILE,
"custom-index-settings/not-parsable.json"
).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"
);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
--- NOT PARSABLE JSON --
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"properties":{
"userField":{
"type":"keyword",
"someUnknownParameter":true
}
}
}