0Pricing
Elasticsearch & Full Text Search Systems · 강의

검색 결과 강조 표시

검색 결과에 강조 표시를 추가하여 반환된 문서에서 일치하는 용어를 시각적으로 두드러지게 하고 사용자 경험을 개선합니다.

검색 결과 강조 표시은(는) CoddyKit의 무료 Elasticsearch & Full Text Search Systems 강의입니다. 이것은 4개 중 3번째 강의입니다. 아래에서 전체 강의를 무료로 읽을 수 있으며, 내장 코드 에디터와 24/7 AI 튜터와 함께 브라우저에서 직접 실습할 수 있습니다. 이 강의는 Elasticsearch & Full Text Search Systems 학습 경로의 일부이며, 진행 상황이 웹과 CoddyKit 앱에 동기화됩니다. Elasticsearch & Full Text Search Systems 강의에는 총 4개의 강의가 포함되어 있습니다.

이 강의의 일부는 아직 번역되지 않았으며 영어로 표시됩니다.

Why Highlight Results?

Imagine searching for a recipe and seeing 'chicken' highlighted exactly where it appears in the ingredients and steps. That's highlighting!

It visually emphasizes the matching terms in your search results, making it much easier for users to quickly scan and find relevant information.

  • Improved User Experience: Users quickly spot why a document is relevant.
  • Contextual Clues: Provides snippets of text around the match, giving context.
  • Faster Information Retrieval: Reduces time spent reading irrelevant parts.

Your First Highlight

Adding basic highlighting to your Elasticsearch search is straightforward. You just need to include a highlight block in your search request.

This block specifies which fields you want to highlight. By default, Elasticsearch wraps the matching terms with <em> and </em> tags.

curl -X GET "localhost:9200/products/_search?pretty" \
  -H 'Content-Type: application/json' \
  -d'
{
  "query": {
    "match": {
      "description": "lightweight laptop"
    }
  },
  "highlight": {
    "fields": {
      "description": {}
    }
  }
}'

Highlighting Specific Fields

In the previous example, we told Elasticsearch to highlight matches found in the description field.

The highlight.fields object is where you list all the fields you want to apply highlighting to. For each field, you can provide an empty object {} for default behavior, or specify custom options.

Only fields that are indexed for full-text search (like text fields) can be highlighted effectively.

Highlighting Multiple Fields

Often, you'll want to highlight matching terms across several fields within the same document, such as a product's title and its content.

Simply add more fields to the fields object in your highlight section. Elasticsearch will process each field independently.

curl -X GET "localhost:9200/articles/_search?pretty" \
  -H 'Content-Type: application/json' \
  -d'
{
  "query": {
    "match": {
      "text": "Elasticsearch indexing"
    }
  },
  "highlight": {
    "fields": {
      "title": {},
      "content": {}
    }
  }
}'

Customizing Highlight Tags

The default <em> tags are fine, but you might want to use different HTML tags or CSS classes for styling your highlighted terms.

You can change these using the pre_tags and post_tags parameters within your highlight block. These parameters accept arrays of strings.

curl -X GET "localhost:9200/products/_search?pretty" \
  -H 'Content-Type: application/json' \
  -d'
{
  "query": {
    "match": {
      "name": "wireless headphones"
    }
  },
  "highlight": {
    "pre_tags": ["<span class=\"highlight\">"],
    "post_tags": ["</span>"],
    "fields": {
      "name": {}
    }
  }
}'

Controlling Snippet Length (fragment_size)

When a document is very long, you usually don't want to return the entire field with highlights. Instead, you want short, relevant snippets.

The fragment_size parameter controls the maximum length (in characters) of the highlighted fragments. Elasticsearch tries to break fragments at sentence boundaries or natural breaks.

curl -X GET "localhost:9200/blogs/_search?pretty" \
  -H 'Content-Type: application/json' \
  -d'
{
  "query": {
    "match": {
      "body": "data analytics"
    }
  },
  "highlight": {
    "fragment_size": 100,
    "fields": {
      "body": {}
    }
  }
}'

Multiple Fragments & No Matches

You can also control the number of snippets returned per field using number_of_fragments. Set it to 0 to return the entire field content as a single fragment (if fragment_size is also 0).

What if there are no matches in a field, but you still want to see its content? Use no_match_size to specify the length of the fragment to return if no matches are found. By default, if there's no match, no fragment is returned for that field.

Advanced Fragment Boundaries

For even more precise control over how fragments are generated, you can use boundary_scanner, boundary_chars, and boundary_max_scan.

  • boundary_scanner: Defines how fragments are split (e.g., sentence, word, chars).
  • boundary_chars: Custom characters to use as fragment boundaries when boundary_scanner is chars.
  • boundary_max_scan: How far to scan for boundary characters.

These are useful for languages without clear sentence structures or for specific content types.

Highlighting from Matched Fields

Sometimes, your search query matches in one field (e.g., content), but you want to highlight the corresponding terms in another field (e.g., a shorter summary or title) for display.

The matched_fields parameter allows you to specify a list of fields that will be used to generate highlights for the current field. This is powerful for showing concise, highlighted snippets from a related, more prominent field.

curl -X GET "localhost:9200/documents/_search?pretty" \
  -H 'Content-Type: application/json' \
  -d'
{
  "query": {
    "match": {
      "full_text": "distributed systems"
    }
  },
  "highlight": {
    "fields": {
      "abstract": {
        "matched_fields": ["full_text"],
        "fragment_size": 100
      }
    }
  }
}'

Highlighting Options Quiz

Which of the following parameters can be used to customize how Elasticsearch generates search result highlights?

Recap: Emphasize Key Finds

You've learned how to bring your search results to life with highlighting! This powerful feature is crucial for improving user experience by visually emphasizing matching terms.

  • We started with basic highlighting using the highlight block.
  • You can specify fields to highlight and customize pre_tags/post_tags.
  • fragment_size and number_of_fragments give you control over snippet length and count.
  • Advanced options like boundary_scanner and matched_fields provide fine-grained control for complex scenarios.

Go forth and make your search results sparkle!

자주 묻는 질문

“검색 결과 강조 표시” 강의는 무료인가요?

네 — “검색 결과 강조 표시” 전체 내용을 이 웹사이트에서 무료로 읽을 수 있습니다. 인터랙티브하게 실습하려면(내장 코드 에디터와 24/7 AI 튜터), CoddyKit PRO로 업그레이드하면 Elasticsearch & Full Text Search Systems 강의 전체를 잠금 해제할 수 있습니다. Elasticsearch & Full Text Search Systems 강의에는 총 4개의 강의가 포함되어 있습니다.

“검색 결과 강조 표시”에서 뭘 배우나요?

검색 결과에 강조 표시를 추가하여 반환된 문서에서 일치하는 용어를 시각적으로 두드러지게 하고 사용자 경험을 개선합니다. 브라우저에서 직접 실행하는 실습 코드로 Elasticsearch & Full Text Search Systems을(를) 배우며, 24/7 AI 튜터가 강의를 진행하면서 질문에 답변해줍니다.

Elasticsearch & Full Text Search Systems을(를) 시작하는 데 경험이 필요한가요?

사전 경험은 필요하지 않습니다. CoddyKit의 Elasticsearch & Full Text Search Systems은(는) 초급자부터 고급 학습자까지를 위해 구성되어 있으므로, 여기서 시작하거나 처음부터 시작할 수 있으며 자신의 속도대로 진행할 수 있습니다. 이것은 4개 중 3번째 강의입니다.

“검색 결과 강조 표시” 강의는 얼마나 걸리나요?

대부분의 CoddyKit 강의는 약 5~10분이 소요됩니다. 각 강의는 간결하고 인터랙티브하여 꾸준한 진행이 가능하며, 웹과 앱에서 중단한 부분부터 바로 시작할 수 있습니다.

이 Elasticsearch & Full Text Search Systems 강의에서 코드를 작성하고 실행할 수 있나요?

네. 모든 Elasticsearch & Full Text Search Systems 강의에는 내장 코드 에디터가 포함되어 있으므로, 브라우저에서 바로 실제 코드를 작성하고 실행한 후 즉시 AI 피드백을 받을 수 있습니다 — 로컬 설정이 필요 없습니다.

이 강의의 모든 강의

  1. 구문 및 근접 검색
  2. 퍼지 및 와일드카드 쿼리
  3. 검색 결과 강조 표시
  4. 패싯 검색을 위한 집계
← Elasticsearch & Full Text Search Systems(으)로 돌아가기