[ES 공식문서] analyzer, search-analyzer

sisi237·2023년 5월 11일
0

elastic-search

목록 보기
4/5

관련: .mapping 파일

analyzer

참고 : https://www.elastic.co/guide/en/elasticsearch/reference/current/analyzer.html

Only text fields support the analyzer mapping parameter.

The analyzer parameter specifies the analyzer used for text analysis 
when indexing or searching a text field.

Unless overridden with the search_analyzer mapping parameter,
this analyzer is used for both index and search analysis.

search-analyzer

참고 : https://www.elastic.co/guide/en/elasticsearch/reference/current/search-analyzer.html

Usually, the same analyzer should be applied at index time and at search time,
to ensure that the terms in the query are in the same format as the terms in the inverted index.
ㄴ 예외 : such as when using the edge_ngram tokenizer for autocomplete or when using search-time synonyms.
ㄴ 일반적으로 색인/검색 시, analyzer 사용하지만 search_analyzer 설정을 통해 더 specify 한다는것 같다

how to Specify an analyzer

참고 : https://www.elastic.co/guide/en/elasticsearch/reference/current/specify-analyzer.html

Elasticsearch offers a variety of ways to specify built-in or custom analyzers:
ㄴ In most cases, a simple approach works best: Specify an analyzer for each text field

How Elasticsearch determines the index analyzer

  1. The analyzer mapping parameter for the field.
  2. The analysis.analyzer.default index setting. << 보통 1번처럼 각 필드에 명시적으로 지정한다
  3. If none of these parameters are specified, 
the standard analyzer is used.
// 1번 사례 
PUT my-index-000001
{
  "mappings": {
    "properties": {
      "title": {
        "type": "text",
        "analyzer": "whitespace"
      }
    }
  }
}

How Elasticsearch determines the search analyzer

In most cases, specifying a different search analyzer is unnecessary.
Doing so could negatively impact relevancy and result in unexpected search results.
ㄴ 분석기 사용을 꼭 해보라는 말

  1. The analyzer parameter in the search query. : 검색 할 때 각 필드에 지정
  2. The search_analyzer mapping parameter for the field. : 색인할 때 각 필드에 지정
  3. The analysis.analyzer.default_search index setting.
  4. The analyzer mapping parameter for the field. << analyzer 를 사용한다는건가 ?
  5. If none of these parameters are specified, the standard analyzer is used.
// 1번 사례
GET my-index-000001/_search
{
  "query": {
    "match": {
      "message": {
        "query": "Quick foxes",
        "analyzer": "stop"
      }
    }
  }
}

// 2번 사례
PUT my-index-000001
{
  "mappings": {
    "properties": {
      "title": {
        "type": "text",
        "analyzer": "whitespace",
        "search_analyzer": "simple"
      }
    }
  }
}

분석기 테스트하는 방법

참고: https://www.elastic.co/guide/en/elasticsearch/reference/current/test-analyzer.html

POST _analyze
{
  "analyzer": "whitespace",
  "text":     "The quick brown fox."
}

POST _analyze
{
  "tokenizer": "standard",
  "filter":  [ "lowercase", "asciifolding" ],
  "text":      "Is this déja vu?"
}

// 인덱스에 설정된 대로 분석기 돌려볼 수 있다 
GET my-index-000001/_analyze 
{
  "field": "my_text", // 프로퍼티 필드 이름 
  "text":  "Is this déjà vu?"
}
profile
자바 서버 개발자

0개의 댓글