0
0
Elasticsearchquery~15 mins

Source filtering in Elasticsearch - Mini Project: Build & Apply

Choose your learning style9 modes available
Source filtering in Elasticsearch queries
📖 Scenario: You work with a collection of books stored in Elasticsearch. Each book has details like title, author, year, and summary. Sometimes you want to get only specific fields from the search results to save bandwidth and focus on what matters.
🎯 Goal: Build an Elasticsearch query that searches for books by author and uses source filtering to return only the title and year fields in the results.
📋 What You'll Learn
Create a query that searches for books where the author is exactly 'Jane Austen'.
Add source filtering to include only the title and year fields in the search results.
Use the Elasticsearch JSON query format.
💡 Why This Matters
🌍 Real World
Source filtering helps reduce the amount of data sent over the network by returning only the fields you need from Elasticsearch search results.
💼 Career
Many jobs working with Elasticsearch require efficient queries that return only relevant data to improve performance and reduce costs.
Progress0 / 4 steps
1
Create the basic search query
Create a JSON object called query with a match clause that searches for author equal to "Jane Austen".
Elasticsearch
Need a hint?

Use the match keyword inside query to find documents where the author is 'Jane Austen'.

2
Add source filtering to include specific fields
Add a _source field to the JSON object that includes only the fields "title" and "year".
Elasticsearch
Need a hint?

The _source field controls which fields are returned. Use a list with the field names.

3
Add a filter to exclude the summary field instead
Modify the _source field to exclude the "summary" field instead of including fields. Use the exclude syntax inside _source.
Elasticsearch
Need a hint?

Use _source as an object with an exclude list to hide fields.

4
Print the final query JSON
Print the complete JSON query object exactly as it is, including the query and _source with exclude.
Elasticsearch
Need a hint?

Use print(query) to show the final JSON object.