What if you could instantly get only the exact data you want from thousands of documents?
Why Source filtering in Elasticsearch? - Purpose & Use Cases
Imagine you have a huge box filled with thousands of documents, but you only want to see a few specific details from each one. Without a way to pick just what you need, you have to open every document and sift through all the information manually.
Manually searching through every document is slow and tiring. It wastes time and computer power because you get overwhelmed with too much unnecessary data. This can cause delays and mistakes when trying to find the important parts.
Source filtering lets you tell Elasticsearch exactly which parts of the documents you want to see. It quickly skips all the extra data and only shows the fields you care about, making your searches faster and cleaner.
{ "query": { "match_all": {} } }{ "_source": ["title", "author"], "query": { "match_all": {} } }Source filtering makes it easy to get just the useful information you need, saving time and making your data clearer and faster to work with.
When searching a library catalog, you might only want to see the book titles and authors, not the full descriptions or reviews. Source filtering helps you get just those details instantly.
Manually handling full documents is slow and overwhelming.
Source filtering lets you pick only the fields you want.
This speeds up searches and simplifies your results.
Practice
_source filtering in Elasticsearch?Solution
Step 1: Understand
_sourcefiltering role_sourcefiltering controls which fields of a document are included in the search response.Step 2: Differentiate from other features
It does not affect indexing or sorting, only what data is returned after a search.Final Answer:
To control which parts of the document are returned in search results -> Option AQuick Check:
Source filtering = control returned fields [OK]
- Confusing source filtering with indexing filters
- Thinking it changes document content
- Assuming it sorts results
password from the search results using source filtering?Solution
Step 1: Recall source filtering syntax
To exclude fields, use"excludes"inside_sourcewith a list of field names.Step 2: Match correct syntax
"_source": { "excludes": ["password"] } uses"excludes": ["password"], which is the correct way to exclude thepasswordfield.Final Answer:
"_source": { "excludes": ["password"] } -> Option CQuick Check:
Exclude fields = use "excludes" key [OK]
- Using "include" to exclude fields
- Using non-existent keys like "filter" or "remove"
- Wrong JSON structure
{
"_source": { "includes": ["title", "author"] },
"query": { "match_all": {} }
}Solution
Step 1: Understand
Theincludesin_sourceincludeskey specifies which fields to return from the document.Step 2: Apply to given query
Since onlytitleandauthorare included, only these fields will appear in the results.Final Answer:
Only the fieldstitleandauthorwill be returned -> Option DQuick Check:
includes fields = return only those fields [OK]
- Thinking includes excludes fields
- Assuming all fields return by default
- Confusing includes with excludes
{
"_source": {
"includes": "title,author"
},
"query": { "match_all": {} }
}Solution
Step 1: Check
Theincludesvalue typeincludesfield expects an array of strings, not a single comma-separated string.Step 2: Identify correct format
It should be["title", "author"]instead of"title,author".Final Answer:
The includes field should be a list, not a comma-separated string -> Option BQuick Check:
includes must be an array, not a string [OK]
- Using comma-separated strings instead of arrays
- Misspelling _source key
- Confusing query errors with source filtering
password and ssn from documents, but also include only the name and email fields explicitly. Which source filtering configuration achieves this correctly?Solution
Step 1: Understand combined includes and excludes
Using bothincludesandexcludeslets you specify fields to return and fields to omit.Step 2: Analyze options
"_source": { "includes": ["name", "email"], "excludes": ["password", "ssn"] } includesnameandemailbut excludespasswordandssn, matching the requirement.Final Answer:
"_source": { "includes": ["name", "email"], "excludes": ["password", "ssn"] } -> Option AQuick Check:
includes + excludes together filters fields precisely [OK]
- Using only includes or excludes, missing fields
- Including fields meant to be excluded
- Misunderstanding combined filtering behavior
Ready to prove it?
Pass the test and this pattern moves unknown
