Synonym Token Filter

Analyzer의 Filter에 사용가능한 필터로, 동의어를 처리할 수 있는 필터

(동이어나 불용어, 사용자 사전과 관련된 부분은 나중에 더 Deep하게 보고, 일단 해당 필터에 대해서만 서술함)

 

Parameters

synonyms : 동의어로 등록(사용)할 단어

synonmyms_path : 파일로 관리할 경우 Elasticearch server의 config 폴더 아래에 생성/지정

 

 

1. 분석기 정의

PUT /test_index_for_synonym
{
  "settings": {
    "analysis": {
      "analyzer": {
        "synonym_analyzer": {
          "tokenizer": "whitespace",
          "filter": [
            "synonym_filter"
          ]
        }
      },
      "filter": {
        "synonym_filter": {
          "type": "synonym",
          "synonyms" : [
            "Harry => 해리"
          ]
        }
      }
    }
  }
}

 

2. 분석 Start

POST test_index_for_synonym/_analyze
{
  "analyzer": "synonym_analyzer",
  "text": "Harry Potter and the Chamber of Secrets"
}

 

3. 분석 결과

{
  "tokens" : [
    {
      "token" : "해리",
      "start_offset" : 0,
      "end_offset" : 5,
      "type" : "SYNONYM",
      "position" : 0
    },
    {
      "token" : "Potter",
      "start_offset" : 6,
      "end_offset" : 12,
      "type" : "word",
      "position" : 1
    },
    {
      "token" : "and",
      "start_offset" : 13,
      "end_offset" : 16,
      "type" : "word",
      "position" : 2
    },
    {
      "token" : "the",
      "start_offset" : 17,
      "end_offset" : 20,
      "type" : "word",
      "position" : 3
    },
    {
      "token" : "Chamber",
      "start_offset" : 21,
      "end_offset" : 28,
      "type" : "word",
      "position" : 4
    },
    {
      "token" : "of",
      "start_offset" : 29,
      "end_offset" : 31,
      "type" : "word",
      "position" : 5
    },
    {
      "token" : "Secrets",
      "start_offset" : 32,
      "end_offset" : 39,
      "type" : "word",
      "position" : 6
    }
  ]
}

 

 

 

 

 

'개발 > Elasticsearch' 카테고리의 다른 글

Local에 docker-compose로 ELK 구성 (+ nori)  (0) 2020.07.03
reindex (index, template migrations)  (0) 2020.07.03
Analyzer 이해하기  (0) 2020.05.20
static index vs dynamic index  (0) 2020.05.20
Mapping Parameters  (0) 2020.05.18

일단 Local에서 ES와 Kibana를 Run 한 뒤 이것저것 테스트한 내용을 서술한다.

(별 것 아닌 내용이지만 남겨놓는게 나을 것 같아서)

 

POST test_index/_analyze
{
  "analyzer": "standard",
  "text": "월, 화, 수, 목, 금, 토, 일"
}

// Result
{
  "tokens" : [
    {
      "token" : "월",
      "start_offset" : 0,
      "end_offset" : 1,
      "type" : "<HANGUL>",
      "position" : 0
    },
    {
      "token" : "화",
      "start_offset" : 3,
      "end_offset" : 4,
      "type" : "<HANGUL>",
      "position" : 1
    },
    {
      "token" : "수",
      "start_offset" : 6,
      "end_offset" : 7,
      "type" : "<HANGUL>",
      "position" : 2
    },
    {
      "token" : "목",
      "start_offset" : 9,
      "end_offset" : 10,
      "type" : "<HANGUL>",
      "position" : 3
    },
    {
      "token" : "금",
      "start_offset" : 12,
      "end_offset" : 13,
      "type" : "<HANGUL>",
      "position" : 4
    },
    {
      "token" : "토",
      "start_offset" : 15,
      "end_offset" : 16,
      "type" : "<HANGUL>",
      "position" : 5
    },
    {
      "token" : "일",
      "start_offset" : 18,
      "end_offset" : 19,
      "type" : "<HANGUL>",
      "position" : 6
    }
  ]
}

 

POST _analyze
{
// analyzer를 지정하지 않을 경우 "standard" analyzer 적용
  "text": "자, 과연 어떻게 나올까? 에라 모르겠다... I don't know!"
}

// Result
{
  "tokens" : [
    {
      "token" : "자",
      "start_offset" : 0,
      "end_offset" : 1,
      "type" : "<HANGUL>",
      "position" : 0
    },
    {
      "token" : "과연",
      "start_offset" : 3,
      "end_offset" : 5,
      "type" : "<HANGUL>",
      "position" : 1
    },
    {
      "token" : "어떻게",
      "start_offset" : 6,
      "end_offset" : 9,
      "type" : "<HANGUL>",
      "position" : 2
    },
    {
      "token" : "나올까",
      "start_offset" : 10,
      "end_offset" : 13,
      "type" : "<HANGUL>",
      "position" : 3
    },
    {
      "token" : "에라",
      "start_offset" : 15,
      "end_offset" : 17,
      "type" : "<HANGUL>",
      "position" : 4
    },
    {
      "token" : "모르겠다",
      "start_offset" : 18,
      "end_offset" : 22,
      "type" : "<HANGUL>",
      "position" : 5
    },
    {
      "token" : "i",
      "start_offset" : 26,
      "end_offset" : 27,
      "type" : "<ALPHANUM>",
      "position" : 6
    },
    {
      "token" : "don't",
      "start_offset" : 28,
      "end_offset" : 33,
      "type" : "<ALPHANUM>",
      "position" : 7
    },
    {
      "token" : "know",
      "start_offset" : 34,
      "end_offset" : 38,
      "type" : "<ALPHANUM>",
      "position" : 8
    }
  ]
}

 

 

 

elasticsearch 7.7 버전에서는 create index 시 analysis를 setting 안으로 넣어주어야 하는 것 같다.

(html_strip Character Filter 예제)

PUT /test_index_for_html_strip
{
  "settings": {
    "index" : {
      "number_of_shards": 5,
      "number_of_replicas": 1
    },
    "analysis": {
    "analyzer": {
      "custom_html_strip_analyzer": {
        "type": "custom",
        "char_filter": [
          "html_strip"
        ],
        "tokenizer": "standard",
        "filter": [
          "lowercase"
        ]
      }
    }
  }
  }
}
POST /test_index_for_html_strip/_analyze
{
  "analyzer": "custom_html_strip_analyzer", 
  "text": "<B>Elasticsearch</B> is cool! <br>"
}

// Result
{
  "tokens" : [
    {
      "token" : "elasticsearch",
      "start_offset" : 3,
      "end_offset" : 20,
      "type" : "<ALPHANUM>",
      "position" : 0
    },
    {
      "token" : "is",
      "start_offset" : 21,
      "end_offset" : 23,
      "type" : "<ALPHANUM>",
      "position" : 1
    },
    {
      "token" : "cool",
      "start_offset" : 24,
      "end_offset" : 28,
      "type" : "<ALPHANUM>",
      "position" : 2
    }
  ]
}

'개발 > Elasticsearch' 카테고리의 다른 글

reindex (index, template migrations)  (0) 2020.07.03
Synonym Token Filter (동의어 처리)  (0) 2020.05.20
static index vs dynamic index  (0) 2020.05.20
Mapping Parameters  (0) 2020.05.18
Elasticsearch APIs  (0) 2020.05.18

마운트

 

느낌상 장비, 인프라. 더 넓게 추리하면 AWS 관련? 일 것 같았다.

 

(배낀곳은 요기 https://jhnyang.tistory.com/12. 근데 내 기준으론 꽤 깊이가 있다. 나중에 다시 봐야함....)

 

Mount = 마운트 = 디스크와 같은 물리적인 장치를 특정 위치, 즉 디렉토리에 연결시켜주는 것

'개발 > what is' 카테고리의 다른 글

Higher order function  (0) 2020.12.30
what difference between uri and url  (0) 2020.06.16
[공지] What is 시리즈  (0) 2020.05.20

이 카테고리는

남에게 차마 대놓고 물어보기에는 민망한 '기본적인' 것 같으면서도 '기본적이지 않은' 것 같은

'애매모호한', 그렇지만 내가 확실하게 '모르는' 또는 '이해안되는' 개념을 짧게 정리하는 곳입니다.

 

한 마디로 몰래 공부해서 적어놓는 일기장 같은거에요.

 

민망하지만 최대한 자세히 모르는 척을 하려고합니다.

'개발 > what is' 카테고리의 다른 글

Higher order function  (0) 2020.12.30
what difference between uri and url  (0) 2020.06.16
What is Mount?  (0) 2020.05.20

+ Recent posts