0
0
Elasticsearchquery~20 mins

First search query in Elasticsearch - Practice Problems & Coding Challenges

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

Given the following Elasticsearch query, which option correctly describes what it returns?

Elasticsearch
{
  "query": {
    "match": {
      "message": "error"
    }
  }
}
AThe query returns documents containing the word 'error' or 'warning'.
BThe query returns all documents regardless of content.
CThe query returns all documents containing the word 'error' in the 'message' field.
DThe query returns documents containing the exact phrase 'error' only.
Attempts:
2 left
💡 Hint

Think about what the match query does in Elasticsearch.

🧠 Conceptual
intermediate
1:30remaining
Which option correctly describes the purpose of the 'size' parameter in a search query?

In an Elasticsearch search query, what does the size parameter control?

AIt controls the number of documents returned in the search results.
BIt controls the maximum size of each document returned.
CIt controls the number of shards to search.
DIt controls the timeout duration for the query.
Attempts:
2 left
💡 Hint

Think about what you want to limit when you get search results.

Predict Output
advanced
2:30remaining
What is the output of this Elasticsearch query with a filter?

Consider this query. What documents will it return?

Elasticsearch
{
  "query": {
    "bool": {
      "must": {
        "match": { "status": "active" }
      },
      "filter": {
        "range": { "age": { "gte": 30 } }
      }
    }
  }
}
ADocuments where 'status' contains 'active' or 'age' is 30 or more.
BDocuments where 'status' contains 'active' and 'age' is 30 or more.
CDocuments where 'status' contains 'active' but 'age' is less than 30.
DDocuments where 'age' is 30 or more regardless of 'status'.
Attempts:
2 left
💡 Hint

Remember how bool queries combine must and filter.

🔧 Debug
advanced
2:00remaining
What error does this Elasticsearch query produce?

Look at this query. What error will Elasticsearch return?

Elasticsearch
{
  "query": {
    "match": {
      "message": ["error", "failure"]
    }
  }
}
AThe query runs successfully and matches documents containing either 'error' or 'failure'.
BThe query returns no results because the list is empty.
CElasticsearch throws a <code>type_error</code> because 'message' field is missing.
DElasticsearch throws a <code>parsing_exception</code> because the 'match' query expects a string, not a list.
Attempts:
2 left
💡 Hint

Check the expected data type for the 'match' query value.

🚀 Application
expert
3:00remaining
How many documents are returned by this complex query?

Given this Elasticsearch query, how many documents will be returned if the index contains 100 documents where 40 have 'status' as 'active', 30 have 'age' ≥ 30, and 20 have both conditions?

Elasticsearch
{
  "query": {
    "bool": {
      "should": [
        { "match": { "status": "active" } },
        { "range": { "age": { "gte": 30 } } }
      ],
      "minimum_should_match": 1
    }
  }
}
A50 documents
B70 documents
C100 documents
D90 documents
Attempts:
2 left
💡 Hint

Use the formula for union of two sets: |A| + |B| - |A ∩ B|.