# 6.5.3 Pattern

&#x20; 앞에서 살펴본 토크나이저들은 다소 차이는 있지만 기본적으로는 공백을 기준으로 하여 텀 들을 분리합니다. 분석 할 데이터가 사람이 읽는 일반적인 문장이 아니라 서버 시스템이나 IoT 장비 등에서 수집된 머신 데이터인 경우 공백이 아닌 쉼표나 세로선 같은 기호가 값 항목의 구분자로 사용되는 경우가 종종 있습니다. 이런 특수한 문자를 구분자로 사용하여 텀을 분리하고 싶은 경우 사용할 수 있는 것이 **Pattern** 토크나이저 입니다.

&#x20; **Pattern** 토크나이저는 분리할 패턴을 기호 또는 Java 정규식 형태로 지정할 수 있습니다. 구분자 지정은 `pattern` 항목에 설정합니다. 다음은 인덱스 **pat\_tokenizer**에 슬래시 `/`를 구분자로 하는 **my\_pat\_tokenizer**라는 사용자 정의 토크나이저를 만들고 **"/usr/share/elasticsearch/bin"** 를 분석하는 예제입니다.

{% code title="pat\_tokenizer 인덱스에 my\_pat\_tokenizer 토크나이저 생성" %}

```javascript
PUT pat_tokenizer
{
  "settings": {
    "analysis": {
      "tokenizer": {
        "my_pat_tokenizer": {
          "type": "pattern",
          "pattern": "/"
        }
      }
    }
  }
}
```

{% endcode %}

{% tabs %}
{% tab title="request" %}
{% code title="my\_pat\_tokenizer 토크나이저로 문장 분석" %}

```javascript
GET pat_tokenizer/_analyze
{
  "tokenizer": "my_pat_tokenizer",
  "text": "/usr/share/elasticsearch/bin"
}
```

{% endcode %}
{% endtab %}

{% tab title="response" %}
{% code title="my\_pat\_tokenizer 토크나이저로 문장 분석 결과" %}

```javascript
{
  "tokens" : [
    {
      "token" : "usr",
      "start_offset" : 1,
      "end_offset" : 4,
      "type" : "word",
      "position" : 0
    },
    {
      "token" : "share",
      "start_offset" : 5,
      "end_offset" : 10,
      "type" : "word",
      "position" : 1
    },
    {
      "token" : "elasticsearch",
      "start_offset" : 11,
      "end_offset" : 24,
      "type" : "word",
      "position" : 2
    },
    {
      "token" : "bin",
      "start_offset" : 25,
      "end_offset" : 28,
      "type" : "word",
      "position" : 3
    }
  ]
}
```

{% endcode %}
{% endtab %}
{% endtabs %}

&#x20; `"pattern": "/"` 같은 단일 기호 외에도 알파벳 대문자를 기준으로 텀을 분리하도록 하는 `"pattern": "(?<=\\p{Lower})(?=\\p{Upper})"` 와 같은 정규식(Regular Expression) 으로도 설정이 가능합니다.


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://esbook.kimjmin.net/06-text-analysis/6.5-tokenizer/6.5.3-pattern.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
