Data stream could not be created because backing index already exists – How to solve this Elasticsearch exception

Opster Team

August-23, Version: 7.1-7.15

Briefly, this error occurs when you’re trying to create a data stream in Elasticsearch, but the backing index with the same name already exists. Elasticsearch uses backing indices to store data stream data, and each backing index must have a unique name. To resolve this issue, you can either delete the existing index if it’s no longer needed, or rename the data stream you’re trying to create. Alternatively, you can rename the existing index if it’s still in use, but this may require changes to any applications or scripts that reference it.

This guide will help you check for common problems that cause the log ” data stream could not be created because backing index [{}] already exists ” to appear. To understand the issues related to this log, read the explanation below about the following Elasticsearch concepts: cluster, metadata, index.

Log Context

Log “data stream could not be created because backing index [{}] already exists” class name is MetadataCreateDataStreamService.java. We extracted the following from Elasticsearch source code for those seeking an in-depth context :

 currentState = metadataCreateIndexService.applyCreateIndexRequest(currentState; createIndexRequest; false);
 } catch (ResourceAlreadyExistsException e) {
 // Rethrow as ElasticsearchStatusException; so that bulk transport action doesn't ignore it during
 // auto index/data stream creation.
 // (otherwise bulk execution fails later; because data stream will also not have been created)
 throw new ElasticsearchStatusException("data stream could not be created because backing index [{}] already exists";
 RestStatus.BAD_REQUEST; e; firstBackingIndexName);
 }
 writeIndex = currentState.metadata().index(firstBackingIndexName);
 }
 assert writeIndex != null;

 

 [ratemypost]