0
0
Elasticsearchquery~10 mins

Source filtering in Elasticsearch - Step-by-Step Execution

Choose your learning style9 modes available
Concept Flow - Source filtering
Send Query with _source filter
Elasticsearch receives query
Check _source filter fields
Include fields
Fetch only specified fields
Return filtered results
Source filtering tells Elasticsearch which fields to include or exclude in the search results, reducing data size.
Execution Sample
Elasticsearch
{
  "query": { "match_all": {} },
  "_source": ["title", "author"]
}
This query fetches all documents but returns only the 'title' and 'author' fields.
Execution Table
StepActionInputResult
1Receive query{"query":{"match_all":{}},"_source":["title","author"]}Query parsed with _source filter
2Check _source filter["title", "author"]Fields to include: title, author
3Fetch documentsAll documents matching match_allDocuments fetched with all fields
4Apply source filteringDocuments with all fieldsDocuments with only title and author fields
5Return resultsFiltered documentsResponse contains only title and author fields
6EndNo more stepsExecution complete
💡 All matching documents returned with only specified fields included
Variable Tracker
VariableStartAfter Step 2After Step 4Final
_source filterundefined["title", "author"]["title", "author"]["title", "author"]
Documents fetchednonenoneonly title and author fieldsonly title and author fields
Key Moments - 3 Insights
Why do only 'title' and 'author' fields appear in the results?
Because the _source filter includes only these fields as shown in execution_table step 4, Elasticsearch excludes all other fields.
What happens if _source filter is omitted?
If omitted, Elasticsearch returns all fields of the documents, as no filtering is applied (not shown in this trace).
Can _source filter exclude fields instead of including?
Yes, you can specify fields to exclude using _source with 'excludes' option, but this example uses inclusion only.
Visual Quiz - 3 Questions
Test your understanding
Look at the execution_table, what fields are included after step 4?
A["title", "author"]
B["title", "author", "date"]
CAll fields
DNo fields
💡 Hint
Check the 'Result' column at step 4 in execution_table
At which step does Elasticsearch apply the source filtering?
AStep 2
BStep 4
CStep 3
DStep 5
💡 Hint
Look for the step where documents are filtered to only specified fields in execution_table
If the _source filter was removed, how would the 'Documents fetched' variable change after step 4?
AIt would remain only title and author fields
BIt would be empty
CIt would include all fields
DIt would include only excluded fields
💡 Hint
Refer to key_moments about what happens if _source filter is omitted
Concept Snapshot
Source filtering in Elasticsearch lets you specify which fields to include or exclude in search results.
Use the _source parameter with an array of fields to include or an object with includes/excludes.
This reduces data size and improves performance by returning only needed fields.
Example: {"_source": ["title", "author"]} returns only those fields.
If omitted, all fields are returned by default.
Full Transcript
Source filtering is a way to tell Elasticsearch which fields you want in your search results. When you send a query with the _source filter, Elasticsearch reads the fields you want to include or exclude. It fetches all matching documents but only returns the specified fields. This makes the response smaller and faster to handle. For example, if you ask for only 'title' and 'author', Elasticsearch will return documents with just those fields. If you don't use source filtering, all fields come back by default. This trace shows each step from receiving the query, checking the filter, fetching documents, applying the filter, and returning the results.