0
0
Elasticsearchquery~20 mins

Full-text search engine concept in Elasticsearch - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Full-text Search 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 Elasticsearch query?

Given the following Elasticsearch query, what will be the total number of hits returned?

Elasticsearch
{
  "query": {
    "match": {
      "description": "quick brown fox"
    }
  }
}
AThe query returns documents only if the description field contains the word "quick" and "fox" but not "brown".
BThe query returns all documents containing the exact phrase "quick brown fox".
CThe query returns documents that do not contain any of the words "quick", "brown", or "fox".
DThe query returns documents containing any of the words "quick", "brown", or "fox" in the description field.
Attempts:
2 left
💡 Hint

Remember that match queries analyze the text and look for any matching terms.

🧠 Conceptual
intermediate
1:30remaining
Which Elasticsearch component is responsible for scoring documents?

In Elasticsearch, which component calculates how relevant a document is to a search query?

AThe Scoring Algorithm (e.g., BM25)
BThe Inverted Index
CThe Document Store
DThe Query Parser
Attempts:
2 left
💡 Hint

Think about how Elasticsearch ranks documents by relevance.

🔧 Debug
advanced
2:30remaining
Why does this Elasticsearch query return zero hits?

Consider this query that returns zero hits even though documents exist with the term "Elasticsearch" in the title:

{
  "query": {
    "term": {
      "title": "Elasticsearch"
    }
  }
}

Why does it return zero hits?

ABecause the <code>term</code> query only works on numeric fields, not text fields.
BBecause the query syntax is invalid and causes a parsing error.
CBecause the <code>term</code> query does not analyze the input and the field is analyzed, so the exact term "Elasticsearch" does not match the indexed tokens.
DBecause the field "title" does not exist in the index mapping.
Attempts:
2 left
💡 Hint

Think about how term queries differ from match queries regarding analysis.

📝 Syntax
advanced
2:00remaining
Which option is a valid Elasticsearch bool query combining must and must_not?

Choose the correct JSON syntax for a bool query that must match "python" in the content field and must not match "java" in the content field.

A{ "bool": { "must": [ { "match": { "content": "python" } } ], "must_not": [ { "match": { "content": "java" } } ] } }
B{ "bool": { "must": { "match": { "content": "python" } }, "must_not": [ { "match": { "content": "java" } } ] } }
C{ "bool": { "must": { "match": { "content": "python" } }, "must_not": { "match": { "content": "java" } } } }
D{ "bool": { "must": [ { "match": { "content": "python" } } ], "must_not": { "match": { "content": "java" } } } }
Attempts:
2 left
💡 Hint

Remember that must and must_not expect arrays of queries.

🚀 Application
expert
3:00remaining
How to implement a phrase search with slop in Elasticsearch?

You want to find documents where the phrase "quick fox" appears in the text field, but you want to allow up to 2 words between "quick" and "fox". Which query achieves this?

A{ "match": { "text": { "query": "quick fox", "slop": 2 } } }
B{ "match_phrase": { "text": { "query": "quick fox", "slop": 2 } } }
C{ "term": { "text": "quick fox" } }
D{ "match_phrase": { "text": { "query": "quick fox", "boost": 2 } } }
Attempts:
2 left
💡 Hint

Use the query type that supports phrase matching with slop.