Bird
Raised Fist0
Elasticsearchquery~20 mins

Multi-match query in Elasticsearch - Practice Problems & Coding Challenges

Choose your learning style10 modes available
Challenge - 5 Problems
🎖️
Multi-match Query Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediate
2:00remaining
What is the output of this multi-match query?

Given the following Elasticsearch multi-match query, what will be the value of hits.total.value if the index contains 3 documents matching the query?

Elasticsearch
{
  "query": {
    "multi_match": {
      "query": "quick brown fox",
      "fields": ["title", "description"]
    }
  }
}
A3
B0
CError: missing operator
D1
Attempts:
2 left
💡 Hint

Multi-match queries search multiple fields and return all matching documents.

🧠 Conceptual
intermediate
1:30remaining
Which option best describes the type parameter in a multi-match query?

In an Elasticsearch multi-match query, what does the type parameter control?

AThe output format of the search results
BThe way the query terms are matched across fields
CThe type of documents to search
DThe index to run the query on
Attempts:
2 left
💡 Hint

Think about how the query behaves when matching terms in multiple fields.

🔧 Debug
advanced
2:00remaining
What error does this multi-match query produce?

Consider this multi-match query with a syntax mistake. What error will Elasticsearch return?

Elasticsearch
{
  "query": {
    "multi_match": {
      "query": "search text",
      "fields": "title description"
    }
  }
}
ANo error, query runs successfully
BError: missing query parameter
CSyntaxError: fields must be an array
DTypeError: query must be a string
Attempts:
2 left
💡 Hint

Check the type of the fields parameter.

📝 Syntax
advanced
2:00remaining
Which option correctly uses fuzziness in a multi-match query?

Choose the valid multi-match query that applies fuzziness to allow approximate matches.

A{ "query": { "multi_match": { "query": "apple", "fields": "name", "fuzziness": 2 } } }
B{ "query": { "multi_match": { "query": "apple", "fields": ["name"] } } }
C{ "query": { "multi_match": { "query": "apple", "fields": ["name"], "fuzziness": true } } }
D{ "query": { "multi_match": { "query": "apple", "fields": ["name"], "fuzziness": "AUTO" } } }
Attempts:
2 left
💡 Hint

Fuzziness must be a string like "AUTO" or a number, and fields must be an array.

🚀 Application
expert
3:00remaining
How many documents will match this multi-match query with operator set to and?

Assume the index has these documents:

  • Doc1: title="fast fox", description="quick brown animal"
  • Doc2: title="slow fox", description="lazy brown animal"
  • Doc3: title="fast dog", description="quick brown animal"

What is the number of documents matched by this query?

Elasticsearch
{
  "query": {
    "multi_match": {
      "query": "quick brown",
      "fields": ["title", "description"],
      "operator": "and"
    }
  }
}
A2
B3
C1
D0
Attempts:
2 left
💡 Hint

With operator set to and, all query terms must appear in the fields.

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

  1. 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.
  2. 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.
  3. Final Answer:

    To search multiple fields with a single query -> Option A
  4. 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"?
easy
A. { "multi_match": { "query": "apple", "fields": ["title", "description"] } }
B. { "match": { "query": "apple", "fields": ["title", "description"] } }
C. { "multi_match": { "fields": ["title", "description"] } }
D. { "multi_match": { "query": "apple" } }

Solution

  1. Step 1: Identify required keys in multi-match query

    A multi-match query requires a "query" key with the search term and a "fields" key listing the fields to search.
  2. Step 2: Check each option for correct syntax

    { "multi_match": { "query": "apple", "fields": ["title", "description"] } } correctly includes both "query" and "fields" keys. { "match": { "query": "apple", "fields": ["title", "description"] } } uses "match" instead of "multi_match". { "multi_match": { "fields": ["title", "description"] } } misses the "query" key. { "multi_match": { "query": "apple" } } misses the "fields" key.
  3. Final Answer:

    { "multi_match": { "query": "apple", "fields": ["title", "description"] } } -> Option A
  4. Quick Check:

    multi_match needs query and fields [OK]
Hint: multi_match needs both query and fields keys [OK]
Common Mistakes:
  • Using 'match' instead of 'multi_match'
  • Omitting the 'query' key
  • Omitting the 'fields' key
3. Given this multi-match query, what will be the effect?
{
  "multi_match": {
    "query": "quick fox",
    "fields": ["title", "content"],
    "type": "phrase"
  }
}
medium
A. Searches only the title field for the phrase "quick fox"
B. Searches for documents containing "quick" or "fox" anywhere in title or content
C. Searches for documents where "quick fox" appears as a phrase in either title or content
D. Searches for documents with exact match "quick fox" in all fields

Solution

  1. Step 1: Understand the 'type' parameter in multi-match

    The "type": "phrase" option makes the query look for the exact phrase "quick fox" in the specified fields.
  2. Step 2: Check fields and matching behavior

    The fields are "title" and "content", so the phrase must appear in either field, not necessarily both.
  3. Final Answer:

    Searches for documents where "quick fox" appears as a phrase in either title or content -> Option C
  4. Quick Check:

    type phrase = exact phrase match in fields [OK]
Hint: type phrase means exact phrase search [OK]
Common Mistakes:
  • Thinking it searches for words separately (not phrase)
  • Assuming it searches only one field
  • Believing it requires phrase in all fields
4. Identify the error in this multi-match query:
{
  "multi_match": {
    "query": "data",
    "fields": "title, description"
  }
}
medium
A. "query" should be an array of words
B. "fields" should be an array, not a string
C. "multi_match" should be "match"
D. "fields" should be omitted for multi-match

Solution

  1. Step 1: Check the type of "fields" value

    The "fields" key must be an array of field names, not a single string with commas.
  2. Step 2: Validate other keys

    The "query" key is correctly a string. "multi_match" is the correct query type. "fields" should not be omitted.
  3. Final Answer:

    "fields" should be an array, not a string -> Option B
  4. 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?
hard
A. { "multi_match": { "query": "coffee", "fields": ["title", "description", "tags"], "boost": 3 } }
B. { "multi_match": { "query": "coffee", "fields": ["title", "description^3", "tags"] } }
C. { "multi_match": { "query": "coffee", "fields": ["title", "description", "tags"], "type": "boost" } }
D. { "multi_match": { "query": "coffee", "fields": ["title^3", "description", "tags"] } }

Solution

  1. Step 1: Understand field boosting syntax

    To give more importance to a field, add a caret (^) and a boost number after the field name, e.g., "title^3".
  2. Step 2: Check each option for correct boosting

    { "multi_match": { "query": "coffee", "fields": ["title^3", "description", "tags"] } } boosts "title" by 3, others default. { "multi_match": { "query": "coffee", "fields": ["title", "description^3", "tags"] } } boosts "description" incorrectly. { "multi_match": { "query": "coffee", "fields": ["title", "description", "tags"], "boost": 3 } } tries to boost all fields equally with "boost" key, which is invalid here. { "multi_match": { "query": "coffee", "fields": ["title", "description", "tags"], "type": "boost" } } uses an invalid "type" value.
  3. Final Answer:

    { "multi_match": { "query": "coffee", "fields": ["title^3", "description", "tags"] } } -> Option D
  4. Quick Check:

    Use ^number to boost fields [OK]
Hint: Boost fields with ^number after field name [OK]
Common Mistakes:
  • Boosting wrong field
  • Using 'boost' key incorrectly
  • Setting invalid 'type' value
Recommended

Ready to prove it?

Pass the test and this pattern moves unknown strong while earning +1 Grip toward your certificate.

10 questions~5 mineasy hard