Briefly, this error occurs when Elasticsearch is unable to filter the source data due to incorrect or invalid filter queries. This could be due to syntax errors, incorrect field names, or unsupported filter types. To resolve this issue, you can: 1) Check and correct the syntax of your filter query. 2) Verify that the field names in your filter query match those in your data source. 3) Ensure that the filter types you’re using are supported by Elasticsearch. 4) If the error persists, consider simplifying your filter query or breaking it down into smaller parts to identify the problematic section.
This guide will help you check for common problems that cause the log ” Error filtering source ” to appear. To understand the issues related to this log, read the explanation below about the following Elasticsearch concepts: source, search.
Overview
When a document is sent for indexing, Elasticsearch indexes all the fields in the format of an inverted index, but it also keeps the original JSON document in a special field called _source.
Examples
Disabling source field in the index:
PUT /api-logs?pretty { "mappings": { "_source": { "enabled": false } } }
Store only selected fields as a part of _source field:
PUT api-logs { "mappings": { "_source": { "includes": [ "*.count", "error_info.*" ], "excludes": [ "error_info.traceback_message" ] } } }
Including only selected fields using source filtering:
GET api-logs/_search { "query": { "match_all": {} }, "_source": { "includes": ["api_name","status_code", "*id"] } }
Notes
The source field brings an overhead of extra storage space but serves special purposes such as:
- Return as a part of the response when a search query is executed.
- Used for reindexing purpose, update and update_by_query operations.
- Used for highlighting, if the field is not stored, it means the field is not set as “store to true” inside the mapping.
- Allows selection of fields to be returned.
The only concern with source field is the extra storage usage on disk. But this storage space used by source field can be optimized by changing compression level to best_compression. This setting is done using index.codec parameter.
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.
Log Context
Log “Error filtering source” class name is FetchSourcePhase.java. We extracted the following from Elasticsearch source code for those seeking an in-depth context :
try { final int initialCapacity = nestedHit ? 1024 : Math.min(1024; source.internalSourceRef().length()); hitContext.hit().sourceRef(objectToBytes(value; source.sourceContentType(); initialCapacity)); } catch (IOException e) { throw new ElasticsearchException("Error filtering source"; e); } } @Override public MapgetDebugInfo() {
[ratemypost]