Briefly, this error occurs when Elasticsearch tries to create a temporary index to apply an alias action, but fails due to issues like insufficient disk space, incorrect permissions, or a conflict with an existing index. To resolve this, ensure there’s enough disk space and correct permissions are set. Also, check for any existing index that might be causing a conflict. If there’s one, consider deleting or renaming it. Additionally, verify your alias action and ensure it’s correctly configured.
This guide will help you check for common problems that cause the log ” [{}] failed to temporary create in order to apply alias action ” to appear. To understand the issues related to this log, read the explanation below about the following Elasticsearch concepts: alias, aliases, cluster, index and metadata.
Quick links:
- Overview – Data Stream Aliases and Index Aliases
- Creating and removing aliases
- Alias use cases
- Notes and common problems
Overview
There are two types of aliases:
- Data Stream Aliases: An alias for a data stream refers to one or more data streams. The names of data streams will be referred to by data stream aliases. In the cluster state, data stream aliases are kept distinct from data streams.
- Index Aliases: An index alias points to one or more indices.
The master node manages the cluster state, which includes aliases.
Creating and removing aliases
Creating an alias on a single index:
POST /_aliases?pretty { "actions": [ { "add": { "index": "index_1", "alias": "alias_1" } } ] }
Creating an alias that is tied to more than one index:
POST /_aliases?pretty { "actions": [ { "add": { "index": "index_1", "alias": "alias_1" } }, { "add": { "index": "index_2", "alias": "alias_1" } } ] }
Listing out all of the available aliases in an Elasticsearch cluster:
GET _cat/aliases
Removing an alias:
POST /_aliases?pretty { "actions": [ { "remove": { "index": "index_2", "alias": "alias_1" } } ] }
Alias use cases
Aliases are used for multiple purposes such as to search across more than one index with a single name, perform the reindexing process with zero downtime and query data based on predefined filters. Below are 6 different use cases for aliases.
1. Filter-based aliases to limit access to data
One use case is making a filter-based alias, which is quite useful when you need to limit access to data. When a query is executed, an alias can apply a filter automatically.
For example, consider an index named `opster-idx`, having an alias that points to the groups that contain the `opster` company, so you can create an alias that handles this filtering automatically as shown in the steps below.
Index documents:
PUT /opster-idx/_doc/1 { "title": "Taking Care of Your Entire Search Operation", "company": "Opster" }
PUT /opster-idx/_doc/2 { "title": "Streaming service", "company": "XYZ" }
Add the query to the actions in the `filter` param to create a filter alias. The query here is used to limit the documents that the alias can access.
POST /_aliases?pretty { "actions": [ { "add": { "index": "opster-idx", "alias": "opster-alias", "filter": { "term": { "company": "opster" } } } } ] }
While you perform a match-all query on `opster-alias`, only the documents that match the term query (which was added when building filter alias, i.e. documents with company name equal to `opster`) will appear in the search results.
Search query:
GET opster-alias/_search { "query":{ "match_all":{} } }
Search response:
"hits": { "total": { "value": 1, "relation": "eq" }, "max_score": 1.0, "hits": [ { "_index": "opster-idx", "_id": "1", "_score": 1.0, "_source": { "title": "Taking Care of Your Entire Search Operation", "company": "Opster" } } ] }
Now if you try to query those documents that have the company name, “XYZ”, as follows:
GET opster-alias/_search { "query": { "match": { "company": "XYZ" } } }
The search response will be:
"hits": { "total": { "value": 0, "relation": "eq" }, "max_score": null, "hits": [] }
2. Combining routing with aliases
When searching and indexing, the following example will filter out the company `opster` and add `1` to the route to limit where searches are done.
Routing is a string value that is used to route indexing and search operations to a specific shard.
POST /_aliases?pretty { "actions": [ { "add": { "index": "index_1", "alias": "alias_2", "filter": { "term": { "company": "opster" } }, "routing": "1" } } ] }
3. Transitioning to new indices
You can use aliases when your application needs to seamlessly transition from an old index to a new index with no downtime.
4. Creating sliding windows into distinct indices
For example, if you construct daily indices for your data, you might wish to establish an alias named `last-7-days` to produce a sliding window of the data from the previous seven days. Then, each day, when you create a new daily index, you may add it to the alias and delete the 8-day old index at the same time.
5. Aliases and ILM for updating or deleting documents
You can use an index alias and index template with ILM to manage and roll over the alias’s indices if you need to update or delete existing documents across numerous indices frequently.
6. Querying data from a frozen index
When using ILM, If you still need to query data from a frozen index, you can use the alias to do so. Instead of searching for data directly through that index, you may run a search query on the alias, which will increase performance and allow you to get a response with fewer resources.
Notes
- An Alias cannot be used for the indexing process if it points to more than one index. If attempted, Elasticsearch will throw an exception.
- Deleting an alias does not delete the actual index.
Common problems
When you try to index a document into an alias that points to more than one index, Elasticsearch returns an error because it doesn’t know which concrete index the document should be indexed to.
You will get the following error message:
{ "error" : { "root_cause" : [ { "type" : "illegal_argument_exception", "reason" : "no write index is defined for alias [my-alias]. The write index may be explicitly disabled using is_write_index=false or the alias points to multiple indices without one being designated as a write index" } ], "type" : "illegal_argument_exception", "reason" : "no write index is defined for alias [my-alias]. The write index may be explicitly disabled using is_write_index=false or the alias points to multiple indices without one being designated as a write index" }, "status" : 400 }
For a full troubleshooting guide on how to resolve this error, see here.
Overview
An Elasticsearch cluster consists of a number of servers (nodes) working together as one. Clustering is a technology which enables Elasticsearch to scale up to hundreds of nodes that together are able to store many terabytes of data and respond coherently to large numbers of requests at the same time.
Search or indexing requests will usually be load-balanced across the Elasticsearch data nodes, and the node that receives the request will relay requests to other nodes as necessary and coordinate the response back to the user.
Notes and good things to know
The key elements to clustering are:
Cluster State – Refers to information about which indices are in the cluster, their data mappings and other information that must be shared between all the nodes to ensure that all operations across the cluster are coherent.
Master Node – Each cluster must elect a single master node responsible for coordinating the cluster and ensuring that each node contains an up-to-date copy of the cluster state.
Cluster Formation – Elasticsearch requires a set of configurations to determine how the cluster is formed, which nodes can join the cluster, and how the nodes collectively elect a master node responsible for controlling the cluster state. These configurations are usually held in the elasticsearch.yml config file, environment variables on the node, or within the cluster state.
Node Roles – In small clusters it is common for all nodes to fill all roles; all nodes can store data, become master nodes or process ingestion pipelines. However as the cluster grows, it is common to allocate specific roles to specific nodes in order to simplify configuration and to make operation more efficient. In particular, it is common to define a limited number of dedicated master nodes.
Replication – Data may be replicated across a number of data nodes. This means that if one node goes down, data is not lost. It also means that a search request can be dealt with by more than one node.
Common problems
Many Elasticsearch problems are caused by operations which place an excessive burden on the cluster because they require an excessive amount of information to be held and transmitted between the nodes as part of the cluster state. For example:
- Shards too small
- Too many fields (field explosion)
Problems may also be caused by inadequate configurations causing situations where the Elasticsearch cluster is unable to safely elect a Master node. This situation is discussed further in:
Backups
Because Elasticsearch is a clustered technology, it is not sufficient to have backups of each node’s data directory. This is because the backups will have been made at different times and so there may not be complete coherency between them. As such, the only way to backup an Elasticsearch cluster is through the use of snapshots, which contain the full picture of an index at any one time.
Cluster resilience
When designing an Elasticsearch cluster, it is important to think about cluster resilience. In particular – what happens when a single node goes down? And for larger clusters where several nodes may share common services such as a network or power supply – what happens if that network or power supply goes down? This is where it is useful to ensure that the master eligible nodes are spread across availability zones, and to use shard allocation awareness to ensure that shards are spread across different racks or availability zones in your data center.
Log Context
Log “[{}] failed to temporary create in order to apply alias action” classname is MetaDataIndexAliasesService.java.
We extracted the following from Elasticsearch source code for those seeking an in-depth context :
for (ObjectCursorcursor : indexMetaData.getMappings().values()) { MappingMetaData mappingMetaData = cursor.value; indexService.mapperService().merge(mappingMetaData.type(); mappingMetaData.source(); MapperService.MergeReason.MAPPING_RECOVERY; false); } } catch (Exception e) { logger.warn("[{}] failed to temporary create in order to apply alias action"; e; indexMetaData.getIndex()); continue; } indicesToClose.add(indexMetaData.getIndex()); } indices.put(indexMetaData.getIndex(); indexService);