Briefly, this error occurs when an alias (a secondary name for an index) that doesn’t exist is used in an alias filter. This could be due to a typo or the alias not being created. To resolve this issue, you can either correct the alias name if it was a typo or create the alias if it doesn’t exist. Also, ensure that the alias is associated with the correct index. It’s also important to check if the alias was accidentally deleted or not properly initialized during setup.
This guide will help you check for common problems that cause the log ” Unknown alias name was passed to alias Filter ” to appear. To understand the issues related to this log, read the explanation below about the following Elasticsearch concepts: alias, search, filter.
Overview
Search refers to the searching of documents in an index or multiple indices. The simple search is just a GET API request to the _search endpoint. The search query can either be provided in query string or through a request body.
Examples
When looking for any documents in this index, if search parameters are not provided, every document is a hit and by default 10 hits will be returned.
GET my_documents/_search
A JSON object is returned in response to a search query. A 200 response code means the request was completed successfully.
{ "took" : 1, "timed_out" : false, "_shards" : { "total" : 2, "successful" : 2, "failed" : 0 }, "hits" : { "total" : 2, "max_score" : 1.0, "hits" : [ ... ] } }
Notes and good things to know
- Distributed search is challenging and every shard of the index needs to be searched for hits, and then those hits are combined into a single sorted list as a final result.
- There are two phases of search: the query phase and the fetch phase.
- In the query phase, the query is executed on each shard locally and top hits are returned to the coordinating node. The coordinating node merges the results and creates a global sorted list.
- In the fetch phase, the coordinating node brings the actual documents for those hit IDs and returns them to the requesting client.
- A coordinating node needs enough memory and CPU in order to handle the fetch phase.
Overview
When a query is executed, Elasticsearch by default calculates the relevance score of the matching documents. But in some conditions, it does not require scores to be calculated. For instance, if a document falls in the range of two given timestamps or if a document contains a given list of tags. For all these Yes/No criteria, also known as structured search, a filter clause is used.
When it is not desired or not necessary to compute scores, filters should be used instead of queries, as frequently used filters can be cached automatically by Elasticsearch to improve performance.
There are multiple ways to specify filters, such as when using the `filter` and `must_not` parameters of the `bool` query, the `filter` parameter of the `constant_score` query or the `filter` aggregation.
What it is used for
When a query is executed, Elasticsearch by default calculates the relevance score of the matching documents. But in some conditions it does not require scores to be calculated, for instance if a document falls in the range of two given timestamps. For all these Yes/No criteria, a filter clause is used.
Examples
To return all the documents of a given index that fall between a date range, we can use the `range` filter, as shown below:
GET my_index/_search { "query": { "bool": { "filter": [ { "range": { "created_at": { "gte": "2020-01-01", "lte": "2020-01-10" } } } ] } } }
To retrieve all the documents that contain at least one tag from a given list, we can use the `terms` filter, as shown below:
GET my_index/_search { "query": { "bool": { "filter": [ { "terms": { "tags": ["tag1", "tag2", "tag3"] } } ] } } }
To retrieve all the documents that contain a given field having a non-null value, we can use the `exists` filter, as shown below:
GET my_index/_search { "query": { "bool": { "filter": [ { "exists": { "field": "field_name" } } ] } } }
There are many other filters that we can use in order to reduce the document set that needs to be scored, such as `fuzzy`, `prefix`, `wildcard`, `regexp`, `script`, and many more.
It is also worth noting that filters can be combined since the `bool/filter` and `bool/must_not` parameters are arrays. In the example below, we retrieve all documents falling within a data range, containing a list of tags and not having a specific field:
GET my_index/_search { "query": { "bool": { "filter": [ { "range": { "created_at": { "gte": "2020-01-01", "lte": "2020-01-10" } } }, { "terms": { "tags": ["tag1", "tag2", "tag3"] } } ], "must_not": [ { "exists": { "field": "field_name" } } ] } } }
Notes
- Queries are used to find out how relevant a document is to a particular query by calculating a score for each document, whereas filters are used to match certain criteria and are cacheable to enable faster execution.
- Filters do not contribute to scoring and thus are faster to execute.
- There are major changes introduced in Elasticsearch version 2.x onward related to how query and filters are written and performed internally and each newer version comes with its load of new improvements.
Common problems
- The most common problem with filters is incorrect use inside the query. If filters are not used correctly, query performance can be significantly affected. So filters must be used wherever there is scope of not calculating the score.
- Another problem often arises when using date range filters, if “now” is used to represent the current time. It has to be noted that “now” is continuously changing the timestamp and thus Elasticsearch cannot use caching of the response since the data set will keep changing.
Log Context
Log “Unknown alias name was passed to alias Filter” class name is ShardSearchRequest.java. We extracted the following from Elasticsearch source code for those seeking an in-depth context :
}; if (aliasNames.length == 1) { AliasMetadata alias = aliases.get(aliasNames[0]); if (alias == null) { // This shouldn't happen unless alias disappeared after filteringAliases was called. throw new InvalidAliasNameException(index; aliasNames[0]; "Unknown alias name was passed to alias Filter"); } return parserFunction.apply(alias); } else { // we need to bench here a bit; to see maybe it makes sense to use OrFilter BoolQueryBuilder combined = new BoolQueryBuilder();
[ratemypost]