0
0
Elasticsearchquery~20 mins

Highlighting matched text in Elasticsearch - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Highlighting Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
Predict Output
intermediate
2:00remaining
What is the highlighted output for a simple match query?
Given the following Elasticsearch query with highlighting, what will be the highlighted fragment in the search results?
Elasticsearch
{
  "query": {
    "match": {
      "content": "quick brown"
    }
  },
  "highlight": {
    "fields": {
      "content": {}
    }
  }
}
A["The <em>quick</em> <em>brown</em> fox jumps"]
B["The quick brown fox jumps"]
C["The <strong>quick</strong> <strong>brown</strong> fox jumps"]
D["The <highlight>quick</highlight> <highlight>brown</highlight> fox jumps"]
Attempts:
2 left
💡 Hint
Elasticsearch uses tags by default for highlighting matched terms.
🧠 Conceptual
intermediate
2:00remaining
Which option correctly changes the highlight tags?
You want to change the default tags to tags in Elasticsearch highlighting. Which highlight configuration achieves this?
A"highlight": { "fields": { "content": {} }, "tags": ["<strong>", "</strong>"] }
B"highlight": { "fields": { "content": {} }, "highlight_tags": ["<strong>", "</strong>"] }
C"highlight": { "fields": { "content": {} }, "pre_tags": ["<strong>"], "post_tags": ["</strong>"] }
D"highlight": { "fields": { "content": {} }, "wrap_tags": ["<strong>", "</strong>"] }
Attempts:
2 left
💡 Hint
Look for the official parameters to customize highlight tags.
🔧 Debug
advanced
2:30remaining
Why does this highlight query return no highlights?
Consider this Elasticsearch query. Why does it return no highlighted fragments even though the document contains the word 'fox'?
Elasticsearch
{
  "query": {
    "match": {
      "content": "fox"
    }
  },
  "highlight": {
    "fields": {
      "content": { "type": "fvh" }
    }
  }
}
AThe field 'content' is not stored or indexed with term vectors required by 'fvh' highlighter.
BThe 'fvh' highlighter does not support the 'match' query type.
CThe highlight field name 'content' is misspelled.
DThe query syntax is invalid causing no results.
Attempts:
2 left
💡 Hint
The 'fvh' highlighter requires specific field settings.
📝 Syntax
advanced
2:00remaining
Identify the syntax error in this highlight query
Which option contains a syntax error that will cause Elasticsearch to reject the highlight query?
Elasticsearch
{
  "query": {
    "match": {
      "content": "dog"
    }
  },
  "highlight": {
    "fields": {
      "content": {
        "pre_tags": ["<em>"],
        "post_tags": ["</em>"]
      }
    }
  }
}
A "highlight": { "fields": { "content": { "pre_tags": ["<em>"], "post_tags": ["</em>"] } } } }
B{ "highlight": { "fields": { "content": { "pre_tags": ["<em>"], "post_tags": ["</em>"] } } } }
C} } } } ]">me/<"[ :"sgat_tsop" ,]">me<"[ :"sgat_erp" { :"tnetnoc" { :"sdleif" { :"thgilhgih" {
D{ "highlight": { "fields": { "content": { "pre_tags": "<em>", "post_tags": "</em>" } } } }
Attempts:
2 left
💡 Hint
Check the data types of pre_tags and post_tags values.
🚀 Application
expert
2:30remaining
How many highlighted fragments will be returned?
Given this query with highlight settings, how many fragments will Elasticsearch return if the content contains the phrase 'lazy dog' repeated 3 times?
Elasticsearch
{
  "query": {
    "match_phrase": {
      "content": "lazy dog"
    }
  },
  "highlight": {
    "fields": {
      "content": {
        "number_of_fragments": 2,
        "fragment_size": 10
      }
    }
  }
}
A0
B2
C1
D3
Attempts:
2 left
💡 Hint
The number_of_fragments setting limits how many fragments are returned.