'검색엔진'에 해당되는 글 20건

  1. 2018.10.04 [Elasticsearch] _analyze 예제 - 특수문자 제거
  2. 2018.08.01 [Elasticsearch] id max length
  3. 2018.07.25 [Elasticsearch] Dynamic template - _default_ deprecated.
  4. 2018.07.13 [Curator] 5.5 사용해 보기
  5. 2018.07.05 [Elasticsearch] Default field type 값.
  6. 2018.07.03 [Elasticsearch] Nested Query 는 Script Fields 를 지원 하지 않습니다.
  7. 2018.06.28 [Elasticsearch] HighLevelRestClient 를 이용한 Bulk Indexing 로컬 테스트 결과
  8. 2018.06.27 [Elasticsearch] _all field 사용하지 마세요.
  9. 2018.06.27 [Elasticsearch] 6.3 설치 변경 내용
  10. 2018.05.09 [Elasticsearch] Adaptive Replica Selection 기능

[Elasticsearch] _analyze 예제 - 특수문자 제거

Elastic/Elasticsearch 2018. 10. 4. 08:02

색인 시점에 text 에 포함된 특수 문자를 제거 하기 위한 예시 입니다.


[실행]

curl -X POST \

  http://localhost:9200/_analyze \

  -H 'cache-control: no-cache' \

  -H 'content-type: application/json' \

  -d '{

  "tokenizer": "arirang_tokenizer",

  "filter":[

              "lowercase",

              "trim",

              "arirang_filter"

            ],

  "char_filter" : [{

          "type": "pattern_replace",

          "pattern": "\\p{Punct}|\\d",

          "replacement": " "

        }],

  "text": "애플(&<>,./^!@+=;:%)파이"

}'



[결과]

{

    "tokens": [

        {

            "token": "애플",

            "start_offset": 0,

            "end_offset": 2,

            "type": "korean",

            "position": 0

        },

        {

            "token": "파이",

            "start_offset": 18,

            "end_offset": 20,

            "type": "korean",

            "position": 1

        }

    ]

}


:

[Elasticsearch] id max length

Elastic/Elasticsearch 2018. 8. 1. 13:19

IndexRequest 클래스에 보면 id 에 대한 max length 제한이 들어 있습니다.

혹시 몰라 코드 올려 봅니다.


if (id != null && id.getBytes(StandardCharsets.UTF_8).length > 512) {
validationException = addValidationError("id is too long, must be no longer than 512 bytes but was: " +
id.getBytes(StandardCharsets.UTF_8).length, validationException);
}


최대 512 bytes

:

[Elasticsearch] Dynamic template - _default_ deprecated.

Elastic/Elasticsearch 2018. 7. 25. 09:49

늘 그렇지만 다 기억 못합니다.


https://www.elastic.co/guide/en/elasticsearch/reference/current/dynamic-templates.html

https://www.elastic.co/guide/en/elasticsearch/reference/current/default-mapping.html


_default_ 가 deprecated 되었습니다.


이와 더불어 사용시 아래와 같은 에러가 발생을 경험 할 수 있는데요.


org.elasticsearch.index.mapper.MapperParsingException: Failed to parse mapping [_default_]: No field type matched on [integer], possible values are [object, string, long, double, boolean, date, binary]


"mappings": {
"_default_": {
"dynamic_templates": [
{

...중략...

우선  _default_ 는 다른 type name 을 작성해 주시면 됩니다.

원문에서와 같이 _doc 이나 _log 나 default 와 같은...


그리고 저 위에 에러는 dynamic templates 사용 시 field type 정보를 보시면 이해가 되실 겁니다.

우리가 흔히 알고 있는 mapping field type 과 조금 다르기 때문에 잘 인지 하고 계시면 삽질은 피하실 수 있습니다.


https://www.elastic.co/guide/en/elasticsearch/reference/current/dynamic-templates.html#match-mapping-type


match_mapping_type

The match_mapping_type matches on the datatype detected by dynamic field mapping, in other words, the datatype that Elasticsearch thinks the field should have. Only the following datatypes can be automatically detected: boolean, date, double, long, object, string. It also accepts * to match all datatypes.


더불어서 잘못 생성된 템플릿을 삭제해야 할 필요가 있습니다.

가끔 아래와 같은 에러가 발생 하는데 이럴 경우 템플릿을 삭제 후 다시 등록 하시면 됩니다.


https://www.elastic.co/guide/en/elasticsearch/reference/current/indices-templates.html

https://www.elastic.co/guide/en/elasticsearch/reference/current/indices-templates.html#delete


java.lang.IllegalArgumentException: Rejecting mapping update to [monitoring-20180725] as the final mapping would have more than 1 type: [log, doc]


DELETE /_template/template_1


:

[Curator] 5.5 사용해 보기

Elastic/Curator 2018. 7. 13. 19:34

오랜만에 사용해 보려고 했더니 또 기억이나질 않아서 기록해 봅니다.


공식문서)

https://www.elastic.co/guide/en/elasticsearch/client/curator/5.5/index.html


설치)

https://www.elastic.co/guide/en/elasticsearch/client/curator/5.5/pip.html


설치 방법이 예전이랑 좀 달라진게 있더군요.

저는 아래 방법으로 설치 했습니다.


$ pip install --user elasticsearch-curator


실행)

https://www.elastic.co/guide/en/elasticsearch/client/curator/5.5/command-line.html

https://www.elastic.co/guide/en/elasticsearch/client/curator/5.5/singleton-cli.html


$ curator [--config CONFIG.YML] [--dry-run] ACTION_FILE.YML 


이 방식으로 이전 3.x 버전에서는 command 를 주고 사용했었으나 4.2 버전 이후 부터는 Singleton command line interface 를 사용해야 합니다. 


- prefix 방식

$ curator_cli --host localhost --port 9200 show_indices --filter_list '{"filtertype":"pattern", "kind":"prefix", "value":"search-"}'


- regex 방식

$ curator_cli --host localhost --port 9200 show_indices --filter_list '{"filtertype":"pattern", "kind":"regex", "value":"^(search-).*$"}'


예제)

https://www.elastic.co/guide/en/elasticsearch/client/curator/5.5/examples.html


더 많은 예제는 위 문서에서 찾아 보시면서 해보시면 될 것 같습니다.


:

[Elasticsearch] Default field type 값.

Elastic/Elasticsearch 2018. 7. 5. 11:04

elasticsearch 문서 모델링 하면서 잘 알고 있다고 생각 하지만 늘 그렇듯 잘 잊어버립니다.

그래서 올려 봅니다. (어딘가에 글 올려 놓은게 있긴 할테지만.. )



우선, FieldMapper 클래스를 확인 합니다.

여기서 보면 MappedFieldType 클래스로 넘어 가게 됩니다.


그래서 default field type 은 아래와 같습니다.


public MappedFieldType() {
setTokenized(true);
setStored(false);
setStoreTermVectors(false);
setOmitNorms(false);
setIndexOptions(IndexOptions.DOCS_AND_FREQS_AND_POSITIONS);
setBoost(1.0f);
}


:

[Elasticsearch] Nested Query 는 Script Fields 를 지원 하지 않습니다.

Elastic/Elasticsearch 2018. 7. 3. 08:38

안되는 기능입니다.,


{

  "error": {

    "root_cause": [

      {

        "type": "parsing_exception",

        "reason": "[nested] query does not support [script_fields]",

        "line": 22,

        "col": 31

      }

    ],

    "type": "parsing_exception",

    "reason": "[nested] query does not support [script_fields]",

    "line": 22,

    "col": 31

  },

  "status": 400

}


:

[Elasticsearch] HighLevelRestClient 를 이용한 Bulk Indexing 로컬 테스트 결과

Elastic/Elasticsearch 2018. 6. 28. 11:35


arirang plug 을 적용해서 돌려본 실행 속도 입니다.


[DEBUG] 2018-07-02 13:12:18.407 [main] MainIndexer - Bulk operation elapsed time [811.0869750976562] sec

[DEBUG] 2018-07-02 13:14:16.595 [main] MainIndexer - Force merge operation elapsed time [118.18800354003906] sec


[Settings]

"settings":{
"number_of_shards":1,
"number_of_replicas":0,
"index.refresh_interval":"1h",
"index.routing.allocation.require.box_type":"indexing",
"index.similarity.default.type":"BM25",
"index":{
"analysis":{
"analyzer":{
"arirang_custom_analyzer":{
"tokenizer":"arirang_tokenizer",
"filter":[
"lowercase",
"trim",
"custom_synonym",
"arirang_filter"
]
}
},
"filter":{
"custom_synonym":{
"type":"synonym_graph",
"synonyms":[]
}
}
}
}
}


[Mappings]

"mappings" : {
"_doc": {
"_source": {
"enabled": true
},
"dynamic_templates": [
{
"strings": {
"match_mapping_type": "string",
"mapping": {
"type": "text",
"analyzer": "arirang_custom_analyzer",
"fields": {
"raw": {
"type": "keyword",
"ignore_above": 50
}
}
}
}
}
]
}
}





얼마전 밋업에서 김종민님이 공유해 주신 위키피디아 문서를 가지고 테스트한 결과 입니다.

그냥 제가 만든 Indexer 모듈에 대한 성능 테스트용도로 한번 실험 삼아 돌려 본거라 별 도움이 안될 수 있습니다.


아래 문서는 언제까지 올라가 있을지 모르겠습니다.

빨리 받으시면 될 듯 하내요.


문서 다운로드 링크)

https://s3.ap-northeast-2.amazonaws.com/kr.elastic.co/sample-data/kr-wikipedia-dump.json.tar.gz


위키피디아 문서 색인 테스트 결과)

MacBook Pro

CPU 2.8G i7

MEM 16GB

API : HighLevelRestClient

REST API : _bulk

Settings

primary shard : 1

replica shard : 0

refresh_interval : 1h

similarity : BM25

default analyzer (standard)

Mappings

dynamic mapping

Indexing File Source Size 

3.6GB

Indexing Segment File Size (force merge 전)

11 GB

Indexing Segment File Size (force merge 후)

4.28 GB

Bulk Request Thread Size

5

Bulk Request Document Size (per thread)

500

Bulk Indexing / Force Merge Time

[DEBUG] 2018-06-28 11:06:13.780 [main] MainIndexer - Bulk operation elapsed time [366.6780090332031] sec

[DEBUG] 2018-06-28 11:08:22.254 [main] MainIndexer - Force merge operation elapsed time [128.47300720214844] sec

Indexing Documents

Total indexed document are 1020662


결과적으로 튜닝한 내용은 전혀 없고 그냥 색인기 기능 테스트 정도로 보셔도 될 것 같습니다.


:

[Elasticsearch] _all field 사용하지 마세요.

Elastic/Elasticsearch 2018. 6. 27. 12:23

_all 필드는 앞으로 사라질 예정입니다.

그러니 사용하지 않도록 합니다.


기본 _all 필드는 disabled 이기 때문에 별도 mapping 설정에 추가 하지 않으셔도 됩니다.

만약 사용 하실 거라면 아래 문서를 참고하세요.


Reference)

https://www.elastic.co/guide/en/elasticsearch/reference/current/mapping-all-field.html


_all enable 시 아래와 같은 경고 문구를 보실 수 있습니다.


returned 1 warnings: [299 Elasticsearch-6.3.0-424e937 "[_all] is deprecated in 6.0+ and will be

removed in 7.0. As a replacement, you can use [copy_to] on mapping fields to create your own

catch all field." "Wed, 27 Jun 2018 03:14:14 GMT"]


:

[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] Adaptive Replica Selection 기능

Elastic/Elasticsearch 2018. 5. 9. 17:06

6.x 에 추가된 API 중 맘에 드는 것이 있어서 글을 퍼왔습니다.


Reference)

https://www.elastic.co/guide/en/elasticsearch/reference/current/search.html


Adaptive Replica Selection

As an alternative to requests being sent to copies of the data in a round robin fashion, you may enable adaptive replica selection. This allows the coordinating node to send the request to the copy deemed "best" based on a number of criteria:


  • Response time of past requests between the coordinating node and the node containing the copy of the data
  • Time past search requests took to execute on the node containing the data
  • The queue size of the search threadpool on the node containing the data

This can be turned on by changing the dynamic cluster setting cluster.routing.use_adaptive_replica_selection from false to true:


PUT /_cluster/settings

{

    "transient": {

        "cluster.routing.use_adaptive_replica_selection": true

    }

}



위에 기술 되어 있는 것 처럼,

- 기본적으로는 Round Robin 방식으로 동작 합니다.

- 하지만 3가지 기준을 가지고 이 기능은 동작을 합니다.

1. Coordinating node 와 Data node 간의 응답 시간

2. Data node 에서 수행된 시간

3. Data node 의 threadpool queue 크기


이 중에서 가장 좋은 기준을 바탕으로 동작 하게 되는 것입니다.


: