'search'에 해당되는 글 42건

  1. 2022.05.09 [Elastic] Enterprise Search 8.2 구성 해 보기
  2. 2021.11.10 [Arirang] 아리랑 사용 시 startOffset, endOffset 역전 현상
  3. 2021.10.18 [Elasticsearch] Deep Pagination.
  4. 2021.02.09 [Elastic] Enterprise Search - App Search JSON Document.
  5. 2021.02.04 [Elastic] Workplace Search ...
  6. 2020.02.14 [Elasticsearch] App Search 소개.
  7. 2018.10.05 [검색일반] stop token filter 와 char filter
  8. 2018.06.27 [Elasticsearch] Move TransportClient to High Level REST Client
  9. 2018.06.27 [Elasticsearch] 6.3 설치 변경 내용
  10. 2018.04.19 [Elasticsearch] Synonym filter 테스트

[Elastic] Enterprise Search 8.2 구성 해 보기

Elastic 2022. 5. 9. 13:56

Enterprise Search (App Search) 를 사용하기 위해서는 먼저 선행 되어야 하는 것들이 있습니다.

https://www.elastic.co/guide/en/app-search/current/getting-started.html

 

App Search 이외 Workspace Search 도 있습니다.

여기서는 App Search 만 다뤘습니다.

 

1. Elasticsearch 가 설치 되어 있어야 합니다.

Enterprise Search 는 Elasticsearch 를 포함 하고 있지 않습니다.

구성 되어 있는 Elasticsearch Cluster 에 연결 해서 Enterprise Search 를 사용 할 수 있도록 해줍니다.

 

2. Kibana 가 설치 되어 있어야 합니다.

Kibana 가 필요한 이유는 Enterprise Search 의 Web UI 가 Kibana 로 통합 되었기 때문 입니다.

 

3. Enterprise Search 가 설치 되어 있어야 합니다.

Enterprise Search 를 사용하기 위해 필요 하며, Elasticsearch 는 JDK 17 을 요구 하지만, Enterprise Search JDK 11 을 요구 합니다.

사용 하는 JDK 버전을 꼭 확인 하셔야 합니다.

 

 

Elasticsearch 8.2 설치 및 실행)

기본 tar ball 을 다운로드 받고 압축을 해제 한 후 바로 실행 합니다.

전에도 설명 했지만 8.x 부터는 기본 xpack security 기능이 enabled 입니다.

$ bin/elasticsearch
 Elasticsearch security features have been automatically configured!
✅ Authentication is enabled and cluster connections are encrypted.

ℹ️  Password for the elastic user (reset with `bin/elasticsearch-reset-password -u elastic`):
  0*LbX+orEfOCQx2GPRRy

ℹ️  HTTP CA certificate SHA-256 fingerprint:
  961aea7f1014ee94966ed79be09f3f550236389049d41b41c4dbe196e2bf7a22

ℹ️  Configure Kibana to use this cluster:
• Run Kibana and click the configuration link in the terminal when Kibana starts.
• Copy the following enrollment token and paste it into Kibana in your browser (valid for the next 30 minutes):
  eyJ2ZXIiOiI4LjIuMCIsImFkciI6WyIxOTIuMTY4LjAuNzo5MjAwIl0sImZnciI6Ijk2MWFlYTdmMTAxNGVlOTQ5NjZlZDc5YmUwOWYzZjU1MDIzNjM4OTA0OWQ0MWI0MWM0ZGJlMTk2ZTJiZjdhMjIiLCJrZXkiOiJpNWRvcG9BQkhoU20tOF9wY1FVYTpwdUZTMFMtM1J4aVZZUmoyaGJzajZnIn0=

ℹ️  Configure other nodes to join this cluster:
• On this node:
  ⁃ Create an enrollment token with `bin/elasticsearch-create-enrollment-token -s node`.
  ⁃ Uncomment the transport.host setting at the end of config/elasticsearch.yml.
  ⁃ Restart Elasticsearch.
• On other nodes:
  ⁃ Start Elasticsearch with `bin/elasticsearch --enrollment-token <token>`, using the enrollment token that you generated.


Kibana 8.2 설치 및 실행)

기본 tar ball 을 다운로드 받고 압축을 해제 한 후 바로 실행 합니다.

Security Enabled 이기 때문에 Kibana 실행 시 Elasticsearch 에서 생성해 준 코드를 입력해서 연결 합니다.

등록 후 ID, PWD 를 입력 하고 로그인 합니다.

$ bin/kibana
i Kibana has not been configured.

Go to http://localhost:5601/?code=917177 to get started.

# elasticsearch 실행 하면서 생성된 코드를 등록 하고 kibana 구성을 완료 합니다.
# id/pwd 를 입력 하고 로그인 합니다. (역시 elasticsearch 실행 시 생성된 코드를 입력 합니다.)

 

Enterprise Search 8.2 설치 및 실행)

기본 tar ball 을 다운로드 받고 압축을 해제 한 후 바로 실행 합니다.

Enterprise Search 의 경우 필요한 정보는 Elasticsearch 와 Kibana 정보 입니다.

Elasticsearch 의 경우 SSL 연동을 위한 정보도 함께 등록 합니다.

$ bin/enterprise-search
# java 11 버전을 요구 하기 때문에 맞춰서 실행 합니다.

--------------------------------------------------------------------------------

Invalid config file (/Users/henry/Workspace/apps/es8.2.0/enterprise-search-8.2.0/config/enterprise-search.yml):
The setting '#/secret_management/encryption_keys' is not valid
No secret management encryption keys were provided.
Your secrets cannot be stored unencrypted.
You can use the following generated encryption key in your config file to store new encrypted secrets:
todd
secret_management.encryption_keys: [37697db0e75459e7c5e55e6c492c36fde2dc31dcc7b9db9fcc44c702d0a3b9f5]


--------------------------------------------------------------------------------

$ vi config/enterprise-search.yml
secret_management.encryption_keys: [37697db0e75459e7c5e55e6c492c36fde2dc31dcc7b9db9fcc44c702d0a3b9f5]
allow_es_settings_modification: true
elasticsearch.username: elastic
elasticsearch.password: 0*LbX+orEfOCQx2GPRRy
elasticsearch.host: https://127.0.0.1:9200
elasticsearch.ssl.enabled: true
elasticsearch.ssl.certificate_authority: /Users/henry/Workspace/apps/es8.2.0/elasticsearch-8.2.0/config/certs/http_ca.crt
kibana.external_url: http://localhost:5601


# enterprise-search 연동을 위해 kibana 설정을 합니다.
$ vi config/kibana.yml
enterpriseSearch.host: http://localhost:3002


$ bin/enterprise-search
#########################################################

Success! Elastic Enterprise Search is starting successfully.

Advanced tooling and management interfaces are available via Kibana. Learn more about configuring and running
Kibana with Enterprise Search at https://www.elastic.co/guide/en/enterprise-search/master/user-interfaces.html.

In a few moments, you'll be able to access Enterprise Search from Kibana at the following address:

  * Kibana URL: http://localhost:5601/app/enterprise_search/overview

If this is your first time starting Enterprise Search, check the console output above for your user authentication credentials.

Visit the documentation: https://www.elastic.co/guide/en/enterprise-search/master/index.html


WARNING: A new secret session key has been generated.

Set the key in your config file to persist user sessions through process restarts:

secret_session_key: 5c6b7e6034c36ab0753033889e977624e362990f210adac99348e0e94aefb9b758ef8799d8d111b7d7c5c11383a254a50ca5322ed916ce185b2141617aa5924e


#########################################################


Kibana 에 접속해서 Enterprise Search 를 사용해 봅니다.)

# kibana 에 접속 해서 enterprise search 에서 app search 를 생성 합니다.
# app search 에서 engine 생성을 한 후 json 파일을 등록 합니다.
# [ {...}, {...} ] 형태의 개별 문서가 등록이 되어 있어야 하며, bulk request json 과 형식이 다릅니다.
# 문서 등록을 했으면 생성한 엔진으로 접근해서 검색을 실행해 봅니다.
# Relevance Tuning 이나 Search UI 에서 실행 합니다. 또는 Postman 에서 실행 하고자 할 때는
https://www.elastic.co/guide/en/app-search/8.2/search-guide.html
각각의 인증키는 Credentials 에 들어 가면, private-key 와 search-key 가 존재 합니다.

# Endpoint rule
http://localhost:3002/api/as/v1/engines/${ENGINE-NAME}/query_suggestion
http://localhost:3002/api/as/v1/engines/${ENGINE-NAME}/search.json

# Suggestion
curl --location --request POST 'http://localhost:3002/api/as/v1/engines/disney-poc/query_suggestion' \
--header 'Authorization: Bearer search-dupjgg5jdgafcj4cqoykq39k' \
--header 'Content-Type: application/json' \
--data-raw '{"query":"서울"}'

# Search
curl --location --request POST 'http://localhost:3002/api/as/v1/engines/disney-poc/search.json' \
--header 'Authorization: Bearer search-dupjgg5jdgafcj4cqoykq39k' \
--header 'Content-Type: application/json' \
--data-raw '{
    "query":"서울"
}'

# enterprise search 에서 제공 하는 query 에는 QueryDSL 을 사용 할 수 없습니다.
https://www.elastic.co/guide/en/app-search/8.2/search.html#search-api-request-body

# enterprise search 에서 제공 하는 synonyms 기능은 질의 시점에 적용 되는 기능입니다.
https://www.elastic.co/guide/en/app-search/8.2/synonyms.html
Kibana UI 에서 등록 시 처음에 등록 하는 동의어가 원본 동의어가 되며, 이후 등록 하는 value 들이 원본 동의어와 같이 처리가 되어야 하는 동의어가 됩니다.

통신 방법에 따라 사용 유형을 정리해 보면,

Case 1)

Elasticsearch Cluster <--> Enterprise Search <--> Kibana

 

Case 2)

Elasticsearch Cluster <--> Enterprise Search <--> External Search API

 

Vertical Search Engine 으로도 사용이 가능 합니다.

Elasticsearch Cluster <--> Enterprise Search (각 서비스 또는 도메인 별 Enigne 생성) <--> External Search API (Engine 별 Endpoint)

 

단일 클러스터 운영을 하고 여러 Collection(Index) 을 사용하고자 할 때 유용하게 사용 가능해 보입니다.

:

[Arirang] 아리랑 사용 시 startOffset, endOffset 역전 현상

ITWeb/검색일반 2021. 11. 10. 14:24

아리랑 형태소 분석기 에서 synonym filter 사용을 하지 않았는데도 offset 역전 현상이 발생 할 경우가 있습니다.
보통은 synonym filter 로 인해서 발생 하는 경우가 있는데요.
total.dic, extension.dic 에 등록된 단어들이 띄어쓰기 없이 복합명사 처럼 작성이 되었을 경우 간혹 발생 할 수 있습니다.

예)

Input Text : 전문의사시대
Dictionary Text : 전문, 전문의, 의사, 사시, 시대
Analyzed Text : 전문, 전문의, 사시, 의사, 시대

복합명사 사전인 compound.txt 에는 등록이 되어 있지 않습니다.
전문의사시대:전문,의사,시대:0000
로 등록을 하면 원하는 결과를 얻을 수 있고 오류도 없어집니다.

 

에러 유형)

startOffset must be non-negative, and endOffset must be >= startOffset, and offsets must not go backwards ...중략...

 

:

[Elasticsearch] Deep Pagination.

Elastic/Elasticsearch 2021. 10. 18. 10:43

Elasticsearch 레퍼런스 문서 입니다.

 

https://www.elastic.co/guide/en/elasticsearch/reference/current/paginate-search-results.html
Deep pagination 기능 구현을 위해서는 Scroll API 를 더 이상 추천 하지 않습니다.
search_after API 를 이용해서 구현 하는 것을 추천 합니다.

Scroll API 는 실시간 서비스를 위한 용도가 아니며, 전체 데이터(대용량 데이터)에 대한 재색인 또는 재구성을 위한 용도로 사용을 합니다.

 

scroll 보다는 search_after 를 사용하라고 하고 있으며, 두 API 모두 전체 또는 특정 질의 조건에 따라 탐색 및 페이징 처리가 가능 합니다.

 

단, 이 기능을 사용 하실 경우

- Cluster 내 Node 의 자원이 충분한지 확인 하시고

- 실시간 서비스 용도로 사용을 하지 마시고

- 색인 요청은 없는지도 확인 하시고

사용 하시길 추천 드립니다.

:

[Elastic] Enterprise Search - App Search JSON Document.

Elastic 2021. 2. 9. 11:30

App Search 에서 JSON Document 색인을 하려다 보니, 에러가 발생을 해서 기록해 둡니다.

Elasticsearch 에서는 문제가 안되는 부분 입니다.

 

Field 명 작성 시 주의 사항)

- lowercase 로 작성이 되어야 합니다.

 

처음 부터 문서 설계 시 lowercase 로 설계 하시기 바랍니다.

이미 대소문자가 섞여 있는 것들에 대한 추가 작업이 필요 한데 왜 안쓰는지 알겠네요.

:

[Elastic] Workplace Search ...

Elastic 2021. 2. 4. 11:22

업무 협업 도구들이 많이 나오면서 생산 되는 정보와 문서에 대한 검색 Needs 가 생기는 건 자연 스러운 현상이라고 생각 합니다.

개인적으로는 대부분 오픈소스를 이용해서 개발 환경을 구성하고 사용을 하고 있다 보니 비용이 발생 하는 도구를 선택 하기가 쉽지 않은 건 또 다른 현실 인것 같습니다.

 

https://www.elastic.co/guide/en/workplace-search/current/workplace-search-install.html

 

Elastic 사에서 무료로 제공 하고 있는 Workplace Search 라는 것이 있습니다.

Enterprise Search 에서 제공 하는 서비스 입니다.

 

저는 개인적으로 Slack 에 대한 사용을 해보고 싶어서 구성해서 테스트를 진행하려 했는데요.

ㅠ.ㅠ

 

Slack 하필 Content Sources 중 현재 유료 버전에 속한 것중 하나 더라구요.

그냥 이거 무료로 풀어 주시면 참 좋을 텐데 말입니다.

 

Workplace Search 에서 무료로 추가해서 사용 할 수 있으면 너무 편하겠지만 이게 안된다고 하면,

그냥 Slack API 를 이용해서 메시지를 가져와 Elasticsearch 로 직접 색인 하는 방법으로 진행 하면 되긴 합니다.

 

어차피 Enterprise Search 에서 Workplace Search 라는 게 독립적으로 동작 하는 방식이 아닌

    Slack <---> Workplace Search Slack Content Source 등록 <---> Elasticsearch

와 같이 동작 하니까 말이죠.

 

그럼에도 불구하고 Slack, Gmail 을 제외 하고 나머지는 무료 이니 필요 하신 분들은 잘 활용 하시면 업무에 도움이 되지 않을까 생각 합니다.

 

:

[Elasticsearch] App Search 소개.

Elastic/Elasticsearch 2020. 2. 14. 15:44

굉장히 좋은 제품인데 ㅎㅎ 아직 잘 모르시는 분들이 많으신 것 같아서 제가 소개해 보려고 합니다.

이미 Elastic 공홈에는 올라가 있습니다.

 

관련 글)

https://www.elastic.co/kr/blog/automation-through-search-analytics-with-elastic-app-search

https://www.elastic.co/kr/blog/elastic-app-search-now-available-on-elasticsearch-service

https://swiftype.com/documentation/app-search/getting-started

 

기본적으로는 elastic 사가 swiftype 이라는 회사를 합병 하면서 관련 제품이 enable 되었다고 보시면 됩니다.

제 기억에는  샌프란시스코에서 했던 2번째 Elastic{On} 에서 소개가 되었던 것 같습니다.

 

기본 통신 방식은 (글로 작성 하기 때문에 전달이 잘 안될 수도 있으니 양해 바랍니다.)

 

Elasticsearch Cluster <-----> App Search <-----> App Search API <-----> Your Application

 

보셔서 아시겠지만 App Search API 를 이용하기 때문에 기존에 Elasticsearch Cluster 로 질의 하기 위한 별도 API Gateway 나 WAS 를 구현 하셨던 분들은 더 이상 구현 하지 않으셔도 됩니다.

더불어 검색을 통한 사용자 행동로그 역시 요구사항에 따라 다를 수 있지만, App Search 에서 자동으로 수집, 분석을 다 해줍니다.

 

엄청나게 편리 하겠죠!!

 

이 제품을 잘 활용 하시면 실제 구축 시간 절약이 가능하고, 검색관련 전문 지식이 없으셔도 검색 서비스를 잘 운영 할 수 있습니다.

 

한번 시도해 보시죠)

https://www.elastic.co/app-search

https://www.elastic.co/downloads/app-search

https://www.elastic.co/downloads/elasticsearch

 

위에서 말씀 드렸듯이 기본 Elasticsearch 가 설치 되어 있어야 합니다.

다운로드 페이지 보시면 기본 설치 과정에 대한 내용이 있으니 참고 하셔서 좋은 경험해 보시길 바랍니다.

:

[검색일반] stop token filter 와 char filter

ITWeb/검색일반 2018. 10. 5. 14:43

가끔 착각하게 되는 내용이라 기술해 봅니다.


우리가 흔히 이야기 하는 불용어라고 하는 것은 추출된 색인어에 대해서 색인어 처리를 하지 않도록 하는 것입니다.

이것이 stopwords 라고 부르는 것이고 stop token filter 하고 합니다.


analyze 과정에서 char filter 이후 tokenizer 단계에서 사용되는 filter 기능이 되는 것입니다.

다시 말해 색인어 추출 후 적용하는 filter 기능이라고 보시면 됩니다.


그럼 char filter 는 언제 동작 하게 될까요?

이 filter 기능은 색인어 추출 전 그러니까 tokenizer 로 text 가 전달 되기 전에 text 내 불필요한 문자들을 제거 하기 위해 사용을 합니다.

이것이 char filter 가 되겠습니다.


그냥 저 혼자 복습 차원에서 기술해 봤습니다.


https://www.elastic.co/guide/en/elasticsearch/reference/current/analysis-stop-tokenfilter.html

https://www.elastic.co/guide/en/elasticsearch/reference/current/analysis-charfilters.html


:

[Elasticsearch] Move TransportClient to High Level REST Client

Elastic/Elasticsearch 2018. 6. 27. 11:46

이번에 새로 Indexer 모듈을 만들다 보니 아래 문서의 내용을 확인하게 되었습니다.


Reference)

https://www.elastic.co/guide/en/elasticsearch/client/java-api/current/client.html

https://github.com/elastic/elasticsearch/tree/master/client/rest/src/test/java/org/elasticsearch/client


원문발췌)

We plan on deprecating the TransportClient in Elasticsearch 7.0 and removing it completely in 8.0. Instead, you should be using the Java High Level REST Client, which executes HTTP requests rather than serialized Java requests. The migration guidedescribes all the steps needed to migrate.

The Java High Level REST Client currently has support for the more commonly used APIs, but there are a lot more that still need to be added. You can help us prioritise by telling us which missing APIs you need for your application by adding a comment to this issue: Java high-level REST client completeness.

Any missing APIs can always be implemented today by using the low level Java REST Client with JSON request and response bodies.


사실 저도 TransportClient 를 사용하면 version 때문에 고민을 하긴했었는데요.

이 참에 그냥 REST Client 로 넘어 가야 겠다고 생각해서 새로 작성 하였습니다.


기본적인 예제 코드는 아래 내용 참고 하시면 됩니다.


public static void main(String[] args) {
requestRestClient();
}

public static void requestRestClient() {
int numNodes = 5; //randomIntBetween(1, 5);
HttpHost[] hosts = new HttpHost[numNodes];
for (int i = 0; i < numNodes; i++) {
hosts[i] = new HttpHost("localhost", 9200);
}
RestClientBuilder builder = RestClient.builder(hosts);
RestClient restClient = builder.build();

builder.setMaxRetryTimeoutMillis(10000);

builder.setFailureListener(new RestClient.FailureListener() {
@Override
public void onFailure(HttpHost host) {
System.out.println("onFailure");
}
});

builder.setRequestConfigCallback(new RestClientBuilder.RequestConfigCallback() {
@Override
public RequestConfig.Builder customizeRequestConfig(
RequestConfig.Builder requestConfigBuilder) {
return requestConfigBuilder.setSocketTimeout(10000);
}
});

Map<String, String> params = new HashMap<>();
params.put("preference", "_shards:0,1,2,3");

HttpAsyncResponseConsumerFactory.HeapBufferedResponseConsumerFactory consumerFactory =
new HttpAsyncResponseConsumerFactory.HeapBufferedResponseConsumerFactory(
30 * 1024 * 1024);
try {
Response response = restClient
.performRequest("GET", "/hello/_search", params, null, consumerFactory);

System.out.println(response.toString());

// Read Case 1
RequestLine requestLine = response.getRequestLine();
HttpHost host = response.getHost();
int statusCode = response.getStatusLine().getStatusCode();
Header[] headers = response.getHeaders();
String responseBody = EntityUtils.toString(response.getEntity());

System.out.println(requestLine);
System.out.println(host);
System.out.println(statusCode);
System.out.println(headers);
System.out.println(responseBody);

// Read Case 2 - old fashion
BufferedReader reader = new BufferedReader(new InputStreamReader(
response.getEntity().getContent()));

String inputLine;
StringBuffer buffer = new StringBuffer();

while ((inputLine = reader.readLine()) != null) {
buffer.append(inputLine);
}

reader.close();

// System.out.println(buffer.toString());
} catch (IOException e) {
e.printStackTrace();
}

try {
restClient.close();
} catch (IOException e) {
e.printStackTrace();
}
}

public static int randomIntBetween(int min, int max) {
return RandomNumbers.randomIntBetween(random(), min, max);
}

public static Random random() {
return RandomizedContext.current().getRandom();
}




:

[Elasticsearch] 6.3 설치 변경 내용

Elastic/Elasticsearch 2018. 6. 27. 07:54

Elasticsearch 6.3 이 릴리즈 되면서 가장 큰 변화는 Elastic 용과 OSS 용 이렇게 두개로 설치 패키지가 나뉜것입니다.

즉, Elastic 사의 license 를 기반으로 동작하는 x-pack 들을 사용하기 위해서는 Elastic 버전을 설치 하셔야 한다는 이야기 입니다.


Basic  라이센스의 경우 free 이기 때문에 OSS 버전을 설치 하고 사용할 수 있겠다 생각 하시면 안되는 걸 경험 하실 수 있습니다. (제가 그랬습니다 ^^;)


전에는 x-pack 을 elasticsearch-plugin 으로 설치가 가능 했지만 6.3 에서는 지원을 하고 있지 않습니다.

또한 x-pack 을 쓰기 위해서는 default system index 생성이 필요 한데 아래 설정이 되어 있으면 오류가 발생을 하게 됩니다.


action.auto_create_index: false


이 설정은 잘 아시겠지만 index 가 없을 때 자동으로 생성을 하게 해주는 설정인데요.

저는 보안이랑 관리적인 부분에서 disable 하고 사용했었는데 basic 버전을 사용하기 위해서 이 설정을 과감히 포기 했습니다.


몇 가지 removed 된 설정들이 있는데요.

5.x 올라 오면서 변경된 내용과 일부 비슷한 것들이 있어서 링크 겁니다.


[Elasticsearch] 2.4.x to 5.2.x 으로의 elasticsearch.yml

그리고 Elastic 에서 제공하는 Breaking Changes 를 보시는 것도 도움이 됩니다.



정리하면)

1. x-pack 버전과 oss 버전이 있으니 용도와 목적에 맞게 설치 하시면 됩니다.

- basic license 를 사용하기 위해서는 x-pack  버전을 사용하셔야 합니다.


2. x-pack 버전 사용 시 action.auto_create_index: true 로 설정 하셔야 합니다.

- default system index 를 생성 해야 하기 때문입니다.


:

[Elasticsearch] Synonym filter 테스트

Elastic/Elasticsearch 2018. 4. 19. 16:19

커뮤니티에 질문 주신 내용이 있어서 바쁘지만 테스트 결과 공유 드립니다.

커뮤니티에 질문 올려 주신 분이 계셔서 직접 테스트 진행 했습니다.

제가 position 관련 에러 수정을 위한 테스트 시간이 없어서 인명 사전 등록 방법으로 처리 했는데요.

수정이 필요 하시면 KoreanFilter 코드를 수정 하시면 됩니다.


설치 및 테스트 Elasticsearch Version)

6.0.0


Arirang plugin 설치)

$ bin/elasticsearch-plugin install https://github.com/HowookJeong/elasticsearch-analysis-arirang/releases/download/6.0.0/elasticsearch-analysis-arirang-6.0.0.zip


Index 삭제)

DELETE syntest


{

  "error": {

    "root_cause": [

      {

        "type": "index_not_found_exception",

        "reason": "no such index",

        "resource.type": "index_or_alias",

        "resource.id": "syntest",

        "index_uuid": "_na_",

        "index": "syntest"

      }

    ],

    "type": "index_not_found_exception",

    "reason": "no such index",

    "resource.type": "index_or_alias",

    "resource.id": "syntest",

    "index_uuid": "_na_",

    "index": "syntest"

  },

  "status": 404

}


Index 생성)

PUT /syntest

{

  "settings": {

    "index.number_of_shards": 1,

    "index.number_of_replicas": 0,

    "index": {

      "analysis": {

        "analyzer": {

          "arirang_custom": {

            "tokenizer": "arirang_tokenizer",

            "filter": [

              "lowercase",

              "trim",

              "custom_synonym",

              "arirang_filter"

            ]

          }

        },

        "filter": {

          "custom_synonym": {

            "type": "synonym",

            "synonyms": [

              "henry,헨리,앙리",

              "신해철,마왕"

            ]

          }

        }

      }

    }

  }

}


{

  "acknowledged": true,

  "shards_acknowledged": true,

  "index": "syntest"

}


Analyze 실행)

GET /syntest/_analyze

{

  "tokenizer": "arirang_tokenizer",

  "filter": [

    "lowercase",

    "trim",

    "custom_synonym",

    "arirang_filter"

  ],

  "text": "신해철"

}


{

  "tokens": [

    {

      "token": "신해철",

      "start_offset": 0,

      "end_offset": 3,

      "type": "korean",

      "position": 0

    },

    {

      "token": "신해",

      "start_offset": 0,

      "end_offset": 2,

      "type": "korean",

      "position": 0

    },

    {

      "token": "해철",

      "start_offset": 1,

      "end_offset": 3,

      "type": "korean",

      "position": 1

    },

    {

      "token": "마왕",

      "start_offset": 0,

      "end_offset": 3,

      "type": "SYNONYM",

      "position": 1

    }

  ]

}


동의어 처리가 되지 않은 이유)

GET /syntest/_analyze

{

  "tokenizer": "arirang_tokenizer",

  "text": "신해철은 henry"

}


{

  "tokens": [

    {

      "token": "신해철은",

      "start_offset": 0,

      "end_offset": 4,

      "type": "korean",

      "position": 0

    },

    {

      "token": "henry",

      "start_offset": 5,

      "end_offset": 10,

      "type": "word",

      "position": 1

    }

  ]

}


tokenizer 에서 추출한 토큰은 위와 같이 두개 입니다.

아래는 filter 를 적용한 내용입니다.


GET /syntest/_analyze

{

  "tokenizer": "arirang_tokenizer",

  "filter": [

    "lowercase",

    "trim",

    "custom_synonym",

    "arirang_filter"

  ],

  "text": "신해철은 henry"

}


{

  "tokens": [

    {

      "token": "신해철",

      "start_offset": 0,

      "end_offset": 3,

      "type": "korean",

      "position": 0

    },

    {

      "token": "신해철은",

      "start_offset": 0,

      "end_offset": 4,

      "type": "korean",

      "position": 0

    },

    {

      "token": "신해",

      "start_offset": 0,

      "end_offset": 2,

      "type": "korean",

      "position": 0

    },

    {

      "token": "해철",

      "start_offset": 1,

      "end_offset": 3,

      "type": "korean",

      "position": 1

    },

    {

      "token": "철은",

      "start_offset": 2,

      "end_offset": 4,

      "type": "korean",

      "position": 2

    },

    {

      "token": "henry",

      "start_offset": 5,

      "end_offset": 10,

      "type": "word",

      "position": 3

    },

    {

      "token": "헨리",

      "start_offset": 5,

      "end_offset": 10,

      "type": "SYNONYM",

      "position": 3

    },

    {

      "token": "앙리",

      "start_offset": 5,

      "end_offset": 10,

      "type": "SYNONYM",

      "position": 3

    }

  ]

}


위에 추출된 term 목록을 보면 "마왕" 이라는 동의어가 추가 되지 않은것을 볼 수 있습니다.

이것은 두 가지 방법으로 해결이 가능 합니다.

사전에 "신해철" 이라는 인명 사전 정보를 등록 하시면 됩니다.

기본적으로 tokenzier 과정 후 filter 처리가 되면서 사전에 등록된 정보로 term 구성이 되기 때문에 사전에 누락 된 경우는 일반적으로 KoreanFilter 에 의해서 bigram 처리가 됩니다.

다른 한 가지는 position 정보가 구성 시 오류가 나지 않도록 코드를 수정 하는 것입니다.

KoreanFilter 코드를 참고 하셔서 테스트 및 수정 하시면 됩니다.


아래는 사전에 "신해철" 추가 후 실행한 방법 입니다.


GET /syntest/_analyze

{

  "tokenizer": "arirang_tokenizer",

  "filter": [

    "lowercase",

    "trim",

    "arirang_filter",

    "custom_synonym"

  ],

  "text": "신해철은 henry"

}


{

  "tokens": [

    {

      "token": "신해철",

      "start_offset": 0,

      "end_offset": 3,

      "type": "korean",

      "position": 0

    },

    {

      "token": "마왕",

      "start_offset": 0,

      "end_offset": 3,

      "type": "SYNONYM",

      "position": 0

    },

    {

      "token": "henry",

      "start_offset": 5,

      "end_offset": 10,

      "type": "word",

      "position": 1

    },

    {

      "token": "헨리",

      "start_offset": 5,

      "end_offset": 10,

      "type": "SYNONYM",

      "position": 1

    },

    {

      "token": "앙리",

      "start_offset": 5,

      "end_offset": 10,

      "type": "SYNONYM",

      "position": 1

    }

  ]

}


: