Search in sources :

Example 1 with IndexRefreshException

use of org.molgenis.data.index.exception.IndexRefreshException in project molgenis by molgenis.

the class ClientFacade method refreshIndexes.

private void refreshIndexes(List<Index> indexes) {
    if (LOG.isTraceEnabled()) {
        LOG.trace("Refreshing index(es) '{}' ...", toString(indexes));
    }
    String[] indexNames = toIndexNames(indexes);
    RefreshRequest refreshRequest = new RefreshRequest(indexNames);
    RefreshResponse refreshResponse;
    try {
        refreshResponse = client.indices().refresh(refreshRequest, DEFAULT);
    } catch (ElasticsearchException e) {
        if (e.status().getStatus() == 404) {
            throw new UnknownIndexException(indexes.stream().map(Index::getName).toList(), e);
        }
        throw new IndexRefreshException(indexes.stream().map(Index::getName).toList());
    } catch (IOException e) {
        throw new IndexRefreshException(indexes.stream().map(Index::getName).toList(), e);
    }
    if (refreshResponse.getFailedShards() > 0) {
        if (LOG.isErrorEnabled()) {
            LOG.error(stream(refreshResponse.getShardFailures()).map(ShardOperationFailedException::toString).collect(joining("\n")));
        }
        throw new IndexRefreshException(indexes.stream().map(Index::getName).toList());
    }
    if (LOG.isDebugEnabled()) {
        LOG.debug("Refreshed index(es) '{}'", toString(indexes));
    }
}
Also used : RefreshRequest(org.elasticsearch.action.admin.indices.refresh.RefreshRequest) RefreshResponse(org.elasticsearch.action.admin.indices.refresh.RefreshResponse) IndexRefreshException(org.molgenis.data.index.exception.IndexRefreshException) UnknownIndexException(org.molgenis.data.index.exception.UnknownIndexException) Index(org.molgenis.data.elasticsearch.generator.model.Index) ElasticsearchException(org.elasticsearch.ElasticsearchException) IOException(java.io.IOException) ShardOperationFailedException(org.elasticsearch.action.ShardOperationFailedException)

Aggregations

IOException (java.io.IOException)1 ElasticsearchException (org.elasticsearch.ElasticsearchException)1 ShardOperationFailedException (org.elasticsearch.action.ShardOperationFailedException)1 RefreshRequest (org.elasticsearch.action.admin.indices.refresh.RefreshRequest)1 RefreshResponse (org.elasticsearch.action.admin.indices.refresh.RefreshResponse)1 Index (org.molgenis.data.elasticsearch.generator.model.Index)1 IndexRefreshException (org.molgenis.data.index.exception.IndexRefreshException)1 UnknownIndexException (org.molgenis.data.index.exception.UnknownIndexException)1