📖 Scenario: You are building a search feature for an online bookstore. Users want to search for books by matching their search words against multiple fields like title, author, and description.
🎯 Goal: Create an Elasticsearch multi-match query that searches for the word "adventure" in the title, author, and description fields.
📋 What You'll Learn
Create a JSON object called query with a multi_match key
Set the query value inside multi_match to the exact string "adventure"
Set the fields inside multi_match to the exact list ["title", "author", "description"]
Print the complete JSON query object
💡 Why This Matters
🌍 Real World
Multi-match queries are used in search engines to find matches across several fields, improving search relevance for users.
💼 Career
Knowing how to build multi-match queries is essential for roles involving Elasticsearch, such as backend developers, data engineers, and search specialists.
Progress0 / 4 steps
1
Create the base JSON query object
Create a JSON object called query with a multi_match key that contains an empty object.
Elasticsearch
Hint
Start by creating a dictionary named query with a key multi_match that holds an empty dictionary.
2
Add the search term to the multi_match query
Inside the multi_match object in query, add the key query with the exact value "adventure".
Elasticsearch
Hint
Add the key query inside multi_match and set it to the string "adventure".
3
Add the fields list to search in
Inside the multi_match object in query, add the key fields with the exact list value ["title", "author", "description"].
Elasticsearch
Hint
Add the key fields inside multi_match and set it to the list ["title", "author", "description"].
4
Print the complete query JSON
Write a print(query) statement to display the complete multi-match query JSON object.
Elasticsearch
Hint
Use print(query) to show the full JSON query object.
Practice
(1/5)
1. What is the main purpose of a multi-match query in Elasticsearch?
easy
A. To search multiple fields with a single query
B. To update multiple documents at once
C. To delete multiple indexes simultaneously
D. To create multiple indexes in one request
Solution
Step 1: Understand the multi-match query concept
A multi-match query allows searching across several fields in one query, making it easier to find matches in different parts of documents.
Step 2: Compare with other options
The other options describe operations like creating indexes, updating documents, or deleting indexes, which are not the purpose of multi-match queries.
Final Answer:
To search multiple fields with a single query -> Option A
Quick Check:
Multi-match = search multiple fields [OK]
Hint: Multi-match searches many fields at once [OK]
Common Mistakes:
Confusing multi-match with update or delete operations
Thinking it creates or deletes indexes
Assuming it searches only one field
2. Which of the following is the correct syntax to perform a multi-match query searching for the word "apple" in fields "title" and "description"?
The "fields" key must be an array of field names, not a single string with commas.
Step 2: Validate other keys
The "query" key is correctly a string. "multi_match" is the correct query type. "fields" should not be omitted.
Final Answer:
"fields" should be an array, not a string -> Option B
Quick Check:
fields must be array, not comma string [OK]
Hint: Fields must be an array, not a comma string [OK]
Common Mistakes:
Passing fields as a comma-separated string
Changing multi_match to match incorrectly
Thinking query must be an array
5. You want to search for the term "coffee" giving higher importance to the "title" field than "description" and "tags" fields. Which multi-match query correctly applies this weighting?