본문 바로가기
WIKI 기술 지식 베이스

Path hierarchy tokenizer

원문 보기 위키 갱신

출처: 문서

본문

경로 계층 토크나이저

path_hierarchy 토크나이저는 파일 시스템 경로(또는 유사한 계층 구조)를 각 계층 수준에서 토큰으로 분해하여 토큰화해요. 이 토크나이저는 파일 경로, URL 또는 기타 구분된 경로와 같은 계층적 데이터를 작업할 때 특히 유용해요.

사용 예시

다음 예시 요청은 my_index라는 새 인덱스를 생성하고 path_hierarchy 토크나이저를 사용하는 분석기를 구성해요.

PUT /my_index
{
  "settings": {
    "analysis": {
      "tokenizer": {
        "my_path_tokenizer": {
          "type": "path_hierarchy"
        }
      },
      "analyzer": {
        "my_path_analyzer": {
          "type": "custom",
          "tokenizer": "my_path_tokenizer"
        }
      }
    }
  }
}

{% include copy-curl.html %}

생성된 토큰

다음 요청을 사용하여 분석기로 생성된 토큰을 확인해 보세요.

POST /my_index/_analyze
{
  "analyzer": "my_path_analyzer",
  "text": "/users/john/documents/report.txt"
}

{% include copy-curl.html %}

응답에는 생성된 토큰이 포함돼요.

{
  "tokens": [
    {
      "token": "/users",
      "start_offset": 0,
      "end_offset": 6,
      "type": "word",
      "position": 0
    },
    {
      "token": "/users/john",
      "start_offset": 0,
      "end_offset": 11,
      "type": "word",
      "position": 0
    },
    {
      "token": "/users/john/documents",
      "start_offset": 0,
      "end_offset": 21,
      "type": "word",
      "position": 0
    },
    {
      "token": "/users/john/documents/report.txt",
      "start_offset": 0,
      "end_offset": 32,
      "type": "word",
      "position": 0
    }
  ]
}

매개변수

path_hierarchy 토크나이저는 다음 매개변수로 구성할 수 있어요.

매개변수 필수/선택 데이터 유형 설명
delimiter Optional String 경로 구성 요소를 구분하는 데 사용되는 문자를 지정해요. 기본값은 /예요.
replacement Optional String 토큰에서 구분자를 대체하는 데 사용되는 문자를 구성해요. 기본값은 /예요.
buffer_size Optional Integer 버퍼 크기를 지정해요. 기본값은 1024예요.
reverse Optional Boolean true인 경우 토큰을 역순으로 생성해요. 기본값은 false예요.
skip Optional Integer 토큰화할 때 건너뛸 초기 토큰(수준) 수를 지정해요. 기본값은 0이에요.

구분자 및 대체 매개변수 사용 예시

다음 예시 요청은 사용자 정의 delimiter 및 replacement 매개변수를 구성해요.

PUT /my_index
{
  "settings": {
    "analysis": {
      "tokenizer": {
        "my_path_tokenizer": {
          "type": "path_hierarchy",
          "delimiter": "\\",
          "replacement": "\\"
        }
      },
      "analyzer": {
        "my_path_analyzer": {
          "type": "custom",
          "tokenizer": "my_path_tokenizer"
        }
      }
    }
  }
}

{% include copy-curl.html %}

다음 요청을 사용하여 분석기로 생성된 토큰을 확인해 보세요.

POST /my_index/_analyze
{
  "analyzer": "my_path_analyzer",
  "text": "C:\\users\\john\\documents\\report.txt"
}

{% include copy-curl.html %}

응답에는 생성된 토큰이 포함돼요.

{
  "tokens": [
    {
      "token": "C:",
      "start_offset": 0,
      "end_offset": 2,
      "type": "word",
      "position": 0
    },
    {
      "token": """C:\users""",
      "start_offset": 0,
      "end_offset": 8,
      "type": "word",
      "position": 0
    },
    {
      "token": """C:\users\john""",
      "start_offset": 0,
      "end_offset": 13,
      "type": "word",
      "position": 0
    },
    {
      "token": """C:\users\john\documents""",
      "start_offset": 0,
      "end_offset": 23,
      "type": "word",
      "position": 0
    },
    {
      "token": """C:\users\john\documents\report.txt""",
      "start_offset": 0,
      "end_offset": 34,
      "type": "word",
      "position": 0
    }
  ]
}

더 알아보기 (Learn more)