0
0
Elasticsearchquery~10 mins

Highlighting matched text in Elasticsearch - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to specify the field to highlight in an Elasticsearch query.

Elasticsearch
{
  "query": {
    "match": {
      "content": "search text"
    }
  },
  "highlight": {
    "fields": {
      "[1]": {}
    }
  }
}
Drag options to blanks, or click blank then click option'
Acontent
Btitle
Cauthor
Ddate
Attempts:
3 left
💡 Hint
Common Mistakes
Using a field name different from the one in the query.
Forgetting to specify the field inside the highlight fields.
2fill in blank
medium

Complete the code to set the pre-tags for highlighted text in Elasticsearch.

Elasticsearch
{
  "highlight": {
    "pre_tags": ["[1]"],
    "post_tags": ["</em>"],
    "fields": {
      "content": {}
    }
  }
}
Drag options to blanks, or click blank then click option'
A<strong>
B<b>
C<mark>
D<em>
Attempts:
3 left
💡 Hint
Common Mistakes
Using tags that do not match the post-tags.
Using tags that are not valid HTML tags.
3fill in blank
hard

Fix the error in the highlight section to correctly specify multiple fields to highlight.

Elasticsearch
{
  "highlight": {
    "fields": {
      "title": {},
      "[1]": {}
    }
  }
}
Drag options to blanks, or click blank then click option'
Acontent
Bhighlight
Cmatch
Dfields
Attempts:
3 left
💡 Hint
Common Mistakes
Using reserved keywords like fields or match as field names.
Using invalid field names that do not exist in the index.
4fill in blank
hard

Fill both blanks to highlight the field and set the fragment size in Elasticsearch.

Elasticsearch
{
  "highlight": {
    "fields": {
      "[1]": {
        "fragment_size": [2]
      }
    }
  }
}
Drag options to blanks, or click blank then click option'
Acontent
Btitle
C150
D50
Attempts:
3 left
💡 Hint
Common Mistakes
Setting fragment_size to a string instead of a number.
Using a field name that does not match the query.
5fill in blank
hard

Fill all three blanks to highlight a field with custom tags and number of fragments.

Elasticsearch
{
  "highlight": {
    "pre_tags": ["[1]"],
    "post_tags": ["[2]"],
    "fields": {
      "content": {
        "number_of_fragments": [3]
      }
    }
  }
}
Drag options to blanks, or click blank then click option'
A<em>
B</em>
C3
D5
Attempts:
3 left
💡 Hint
Common Mistakes
Mismatching pre and post tags.
Using a string instead of a number for number_of_fragments.