# 6.5.4 Path Hierarchy

&#x20; 디렉토리나 파일 경로 등은 흔하게 저장되는 데이터입니다. 앞의 Pattern 토크나이저에서 **"/usr/share/elasticsearch/bin"** 를 실행했을 때는 디렉토리명 들이 각각 하나의 토큰으로 분리 된 것을 확인했습니다. 이 경우 다른 패스에 있는데 하위 디렉토리 명이 같은 경우 데이터 검색에 혼동이 올 수 있습니다.

&#x20; **Path Hierarchy** 토크나이저를 사용하면 경로 데이터를 계층별로 저장해서 하위 디렉토리에 속한 도큐먼트들을 수준별로 검색하거나 집계하는 것이 가능합니다. 다음은 Path Hierarchy 토크나이저로 **"/usr/share/elasticsearch/bin"** 를 분석하는 예제입니다.

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

```javascript
POST _analyze
{
  "tokenizer": "path_hierarchy",
  "text": "/usr/share/elasticsearch/bin"
}
```

{% endcode %}
{% endtab %}

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

```javascript
{
  "tokens" : [
    {
      "token" : "/usr",
      "start_offset" : 0,
      "end_offset" : 4,
      "type" : "word",
      "position" : 0
    },
    {
      "token" : "/usr/share",
      "start_offset" : 0,
      "end_offset" : 10,
      "type" : "word",
      "position" : 0
    },
    {
      "token" : "/usr/share/elasticsearch",
      "start_offset" : 0,
      "end_offset" : 24,
      "type" : "word",
      "position" : 0
    },
    {
      "token" : "/usr/share/elasticsearch/bin",
      "start_offset" : 0,
      "end_offset" : 28,
      "type" : "word",
      "position" : 0
    }
  ]
}
```

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

&#x20; `delimiter` 항목값으로 경로 구분자를 지정할 수 있습니다. 디폴트는 `/` 입니다. 그리고 `replacement` 옵션을 이용해서 소스의 구분자를 다른 구분자로 대치해서 저장하는 것도 가능합니다. 그 외의 옵션들은 [공식 도큐먼트](https://www.elastic.co/guide/en/elasticsearch/reference/current/analysis-pathhierarchy-tokenizer.html)를 참고하시기 바랍니다.

&#x20; 다음은 인덱스 **hir\_tokenizer**에 `-` 구분자를 `/` 구분자로 대치하는 **my\_hir\_tokenizer**라는 사용자 정의 토크나이저를 만들고 **"one-two-three"** 문장을 분석하는 예제입니다.

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

```javascript
PUT hir_tokenizer
{
  "settings": {
    "analysis": {
      "tokenizer": {
        "my_hir_tokenizer": {
          "type": "path_hierarchy",
          "delimiter": "-",
          "replacement": "/"
        }
      }
    }
  }
}
```

{% endcode %}

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

```javascript
GET hir_tokenizer/_analyze
{
  "tokenizer": "my_hir_tokenizer",
  "text": [
    "one-two-three"
  ]
}
```

{% endcode %}
{% endtab %}

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

```javascript
{
  "tokens" : [
    {
      "token" : "one",
      "start_offset" : 0,
      "end_offset" : 3,
      "type" : "word",
      "position" : 0
    },
    {
      "token" : "one/two",
      "start_offset" : 0,
      "end_offset" : 7,
      "type" : "word",
      "position" : 0
    },
    {
      "token" : "one/two/three",
      "start_offset" : 0,
      "end_offset" : 13,
      "type" : "word",
      "position" : 0
    }
  ]
}
```

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

&#x20;&#x20;


---

# 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.4-path-hierarchy.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.
