Opster Team
Before you begin reading this guide, we recommend you run Elasticsearch Error Check-Up which analyzes 2 JSON files to detect many errors.
To easily locate the root cause and resolve this issue try AutoOps for Elasticsearch & OpenSearch. It diagnoses problems by analyzing hundreds of metrics collected by a lightweight agent and offers guidance for resolving them. Take a self-guided product tour to see for yourself (no registration required).
This guide will help you check for common problems that cause the log ” Ignoring dangled index on node due to an existing alias with the same name ” to appear. To understand the issues related to this log, read the explanation below about the following Elasticsearch concepts: alias, dangled, index, indices and node.
Quick links:
- Overview – Data Stream Aliases and Index Aliases
- Creating and removing aliases
- Alias use cases
- Notes and common problems
Overview
In Elasticsearch, an alias is a secondary name given that refers to a group of data streams or indices. Aliases can be created and removed dynamically using _aliases REST endpoint.
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.
Index and indexing in Elasticsearch - 3 min
Overview
In Elasticsearch, an index (plural: indices) contains a schema and can have one or more shards and replicas. An Elasticsearch index is divided into shards and each shard is an instance of a Lucene index.
Indices are used to store the documents in dedicated data structures corresponding to the data type of fields. For example, text fields are stored inside an inverted index whereas numeric and geo fields are stored inside BKD trees.
Examples
Create index
The following example is based on Elasticsearch version 5.x onwards. An index with two shards, each having one replica will be created with the name test_index1
PUT /test_index1?pretty { "settings" : { "number_of_shards" : 2, "number_of_replicas" : 1 }, "mappings" : { "properties" : { "tags" : { "type" : "keyword" }, "updated_at" : { "type" : "date" } } } }
List indices
All the index names and their basic information can be retrieved using the following command:
GET _cat/indices?v
Index a document
Let’s add a document in the index with the command below:
PUT test_index1/_doc/1 { "tags": [ "opster", "elasticsearch" ], "date": "01-01-2020" }
Query an index
GET test_index1/_search { "query": { "match_all": {} } }
Query multiple indices
It is possible to search multiple indices with a single request. If it is a raw HTTP request, index names should be sent in comma-separated format, as shown in the example below, and in the case of a query via a programming language client such as python or Java, index names are to be sent in a list format.
GET test_index1,test_index2/_search
Delete indices
DELETE test_index1
Common problems
- It is good practice to define the settings and mapping of an Index wherever possible because if this is not done, Elasticsearch tries to automatically guess the data type of fields at the time of indexing. This automatic process may have disadvantages, such as mapping conflicts, duplicate data and incorrect data types being set in the index. If the fields are not known in advance, it’s better to use dynamic index templates.
- Elasticsearch supports wildcard patterns in Index names, which sometimes aids with querying multiple indices, but can also be very destructive too. For example, It is possible to delete all the indices in a single command using the following commands:
DELETE /*
To disable this, you can add the following lines in the elasticsearch.yml:
action.destructive_requires_name: true
Log Context
Log “Ignoring dangled index [{}] on node [{}] due to an existing alias with the same name” classname is LocalAllocateDangledIndices.java.
We extracted the following from Elasticsearch source code for those seeking an in-depth context :
} if (currentState.metaData().hasIndex(indexMetaData.getIndex().getName())) { continue; } if (currentState.metaData().hasAlias(indexMetaData.getIndex().getName())) { logger.warn("ignoring dangled index [{}] on node [{}] due to an existing alias with the same name"; indexMetaData.getIndex(); request.fromNode); continue; } importNeeded = true;
Find & fix Elasticsearch problems
Opster AutoOps diagnoses & fixes issues in Elasticsearch based on analyzing hundreds of metrics.
Fix Your Cluster IssuesConnect in under 2 minutes
Jose Rafaelly
Head of System Engineering at Everymundo