Skip to content

Repository initialization should throw an Exception when index cannot be created [DATAES-481] #1056

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
spring-projects-issues opened this issue Aug 27, 2018 · 1 comment · Fixed by #1637
Assignees
Labels
type: enhancement A general enhancement

Comments

@spring-projects-issues
Copy link

Mateusz Stefek opened DATAES-481 and commented

AbstractElasticSearchRepository creates an index on startup, if it isn't already there. \

If there's an error in this index creation, an exception is swallowed and the error is simply reported into the logs.

This renders the application unusable when the Elasticsearch server is unavailable during the application startup. (IndexNotFoundExceptionis thrown by all the operations on the repository).

I would like to have an option to force the application to crash, if anything fails in this constructor.

	public AbstractElasticsearchRepository(ElasticsearchEntityInformation<T, ID> metadata,
			ElasticsearchOperations elasticsearchOperations) {
		this(elasticsearchOperations);

		Assert.notNull(metadata, "ElasticsearchEntityInformation must not be null!");

		this.entityInformation = metadata;
		setEntityClass(this.entityInformation.getJavaType());
		try {
			if (createIndexAndMapping()) {
				createIndex();
				putMapping();
			}
		} catch (ElasticsearchException exception) {
			LOGGER.error("failed to load elasticsearch nodes : " + exception.getDetailedMessage());
		}
	}

Affects: 3.0.9 (Kay SR9)

@spring-projects-issues spring-projects-issues added the type: enhancement A general enhancement label Dec 31, 2020
@sothawo sothawo self-assigned this Jan 2, 2021
@sothawo sothawo changed the title Allow AbstractElasticsearchRepository to throw an Exception when an index cannot be created [DATAES-481] Repository initialization should throw an Exception when an index cannot be created [DATAES-481] Jan 6, 2021
@sothawo sothawo changed the title Repository initialization should throw an Exception when an index cannot be created [DATAES-481] Repository initialization should throw an Exception when index cannot be created [DATAES-481] Jan 6, 2021
@sothawo
Copy link
Collaborator

sothawo commented Jan 8, 2021

Additional comment: I think we should definitely throw an exception. When creating an index or storing the mapping itself throw an exception, this happens when the entity is configured to have the index created automatically and the index does not exist yet (this last check was not yet in place when this ticket was created). I guess that just logging the exception still comes from the times when there was no check for existing indices, and trying to create an already existing index threw an exception.

sothawo added a commit that referenced this issue Jan 10, 2021
@sothawo sothawo added this to the 4.2 M2 (2021.0.0) milestone Jan 10, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: enhancement A general enhancement
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants