0Pricing
Elasticsearch & Full Text Search Systems · 강의

텍스트 분석기 사용자 지정

검색을 위해 텍스트가 처리되고 어간이 추출되며 색인되는 방식을 제어하도록 특정 필드에 사용자 지정 분석기를 만들고 적용하는 방법을 학습합니다.

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

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

Why Custom Analyzers?

Elasticsearch comes with powerful default text analyzers, but sometimes your data needs a special touch. This is where custom analyzers shine!

They allow you to precisely control how your text fields are processed for search, ensuring optimal relevancy and accuracy for your specific use case.

The Analyzer Recipe

Recall that every analyzer, custom or built-in, follows a three-step process to transform raw text into searchable tokens:

  • Character Filters: Clean up the raw input string (e.g., remove HTML tags).
  • Tokenizer: Breaks the processed string into individual words or tokens.
  • Token Filters: Modifies, adds, or removes tokens (e.g., lowercase, remove stop words, apply stemming).

A custom analyzer lets you pick and choose these ingredients!

Defining Custom Analyzers

You define custom analyzers within an index's settings block, under analysis. This tells Elasticsearch how to process text for that index.

Here's the basic structure for creating a custom analyzer:

PUT /my_custom_index
{
  "settings": {
    "analysis": {
      "analyzer": {
        "my_custom_analyzer": {
          "type": "custom",
          "char_filter": [],
          "tokenizer": "standard",
          "filter": []
        }
      }
    }
  }
}

Custom Character Filters

Character filters are the first step, acting on the raw text. They can remove or replace characters before tokenization. You can define your own or use built-in ones.

  • html_strip: Removes HTML tags.
  • mapping: Replaces specified characters or strings.

Here's how to define a custom mapping filter:

PUT /my_index_with_char_filter
{
  "settings": {
    "analysis": {
      "char_filter": {
        "ampersand_to_and": {
          "type": "mapping",
          "mappings": ["& => and "]
        }
      },
      "analyzer": {
        "my_analyzer": {
          "type": "custom",
          "char_filter": ["ampersand_to_and"],
          "tokenizer": "standard",
          "filter": ["lowercase"]
        }
      }
    }
  }
}

Selecting a Tokenizer

The tokenizer breaks the stream of characters from the character filters into individual tokens (words). Your choice here is crucial for how words are identified.

Common built-in tokenizers you can use in custom analyzers include:

  • standard: Good for most languages, grammar-based.
  • whitespace: Splits text only on whitespace.
  • keyword: Treats the entire input as a single token (useful for exact values).
  • pattern: Splits text based on a regular expression.

Custom Token Filters

Token filters refine the tokens generated by the tokenizer. This is where most of the search logic resides, like handling synonyms or stemming.

You can define custom versions of filters or use built-in ones:

  • lowercase: Converts tokens to lowercase.
  • stop: Removes common, less meaningful words (stop words).
  • synonym: Replaces tokens with their synonyms.
  • stemmer: Reduces words to their root form.

Let's define a custom stop word filter:

PUT /my_index_with_token_filter
{
  "settings": {
    "analysis": {
      "filter": {
        "my_custom_stop_words": {
          "type": "stop",
          "stopwords": ["a", "the", "is", "and", "are"]
        }
      },
      "analyzer": {
        "my_analyzer": {
          "type": "custom",
          "tokenizer": "standard",
          "filter": ["lowercase", "my_custom_stop_words"]
        }
      }
    }
  }
}

Building a Full Custom Analyzer

Now, let's combine these concepts to create a practical custom analyzer for blog post content. It will:

  • Remove HTML tags.
  • Tokenize standard text.
  • Lowercase all tokens.
  • Remove common English stop words.

This analyzer is then applied to the content field.

PUT /blog_posts_index
{
  "settings": {
    "analysis": {
      "char_filter": {
        "html_strip_char_filter": {
          "type": "html_strip"
        }
      },
      "filter": {
        "english_stop_words": {
          "type": "stop",
          "stopwords": ["the", "a", "an", "is", "are"]
        }
      },
      "analyzer": {
        "blog_content_analyzer": {
          "type": "custom",
          "char_filter": ["html_strip_char_filter"],
          "tokenizer": "standard",
          "filter": ["lowercase", "english_stop_words"]
        }
      }
    }
  },
  "mappings": {
    "properties": {
      "content": {
        "type": "text",
        "analyzer": "blog_content_analyzer"
      }
    }
  }
}

Applying to Field Mappings

Once your custom analyzer is defined in the index settings, you apply it to a text field within your index's mapping. This tells Elasticsearch to use your custom logic when indexing and searching that specific field.

You simply specify the analyzer parameter with the name of your custom analyzer:

PUT /blog_posts_index/_mapping
{
  "properties": {
    "content": {
      "type": "text",
      "analyzer": "blog_content_analyzer"
    },
    "title": {
      "type": "text",
      "analyzer": "standard" 
    }
  }
}

Testing with _analyze API

How can you be sure your custom analyzer works as expected? Use the _analyze API! It lets you simulate how text will be processed by any analyzer.

This is an indispensable tool for debugging and validating your text analysis setup.

GET /blog_posts_index/_analyze
{
  "analyzer": "blog_content_analyzer",
  "text": "The <b>quick</b> brown fox jumps over the lazy dog."
}

Quiz Time!

You've learned about the components of a custom analyzer and how to define them. Let's test your knowledge!

Custom Analyzers: Your Search Superpower

Congratulations! You've learned how to harness the power of custom analyzers in Elasticsearch.

  • You can now define custom character filters, tokenizers, and token filters.
  • You know how to combine these components to create a tailor-made analyzer for your data.
  • You understand how to apply this analyzer to specific fields in your mappings.
  • And importantly, you know how to test your analyzer using the _analyze API.

This skill is crucial for building highly relevant and accurate search experiences!

자주 묻는 질문

“텍스트 분석기 사용자 지정” 강의는 무료인가요?

네 — “텍스트 분석기 사용자 지정” 전체 내용을 이 웹사이트에서 무료로 읽을 수 있습니다. 인터랙티브하게 실습하려면(내장 코드 에디터와 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개 중 2번째 강의입니다.

“텍스트 분석기 사용자 지정” 강의는 얼마나 걸리나요?

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

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

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

이 강의의 모든 강의

  1. 분석기, 토크나이저, 필터
  2. 텍스트 분석기 사용자 지정
  3. 부스트와 관련성 점수
  4. 동의어 및 어간 추출
← Elasticsearch & Full Text Search Systems(으)로 돌아가기