'엘라스틱'에 해당되는 글 4건

  1. 2017.04.27 [Elasticsearch] 5.x 용 Arirang 형태소 분석기 사용 시 주의 사항.
  2. 2016.11.24 [Elasticsearch] Lucene Arirang Analyzer Plugin for Elasticsearch 5.0.1
  3. 2016.05.24 [Elasticsearch] BoolQueryBuilder + TermsQueryBuilder 사용 시 minimum_should_match와 min_should_match
  4. 2016.04.26 [Elasticsearch] This Week in Elasticsearch and Apache Lucene - 2016-04-25

[Elasticsearch] 5.x 용 Arirang 형태소 분석기 사용 시 주의 사항.

Elastic/Elasticsearch 2017. 4. 27. 10:05

Elasticsearch에서 아리랑 형태소분석기 사용 시 주의사항)

사실 주의 사항 이라기 보다 1음절 처리에 대한 고민을 해보시면 좋을 것 같다는 의견 드립니다.


2.x 에서 사용하던 arirang 과 lucene 의 버전은 

- morph 1.0.x

- arirang & lucene 5.x

입니다.


5.x 에서 사용하던 arirang 과 lucene 의 버전은

- morph 1.1.0

- arirang & lucene 6.x

입니다.


여기서 arirang morph 쪽 코드가 많이 개선 또는 변경이 되었습니다.

그리고 몇 가지 default 설정 값들에 대한 변화도 있는데요.


제가 발견한 대표적인 문제는 아래와 같습니다.


'울퉁불퉁한' 이라는 source 에 대한 analysis 시 발생을 합니다.


5.x 에서 analyze 한 결과는 아래와 같습니다.

울퉁불퉁한(N)/90:2

울퉁불퉁/Z

한/N

울퉁불퉁(N),하(t),ㄴ(e)/70:2

울퉁/N

불퉁/N


2.x 에서 analyze 한 결과는 아래와 같습니다.

울퉁불퉁(N),하(t),ㄴ(e)/70:2

울퉁/N

불퉁/N


이게 무슨 문제가 되느냐고 할 수 있는데

실제 색인을 실행 하면 position 정보가 5.x 에서 뒤집혀져 색인 되지 않는 문제를 보실 수 있습니다.


5.x 에서 _analyze 한 결과는 아래와 같습니다.

{

  "tokens" : [

    {

      "token" : "울퉁불퉁한",

      "start_offset" : 0,

      "end_offset" : 5,

      "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" : 4,

      "end_offset" : 5,

      "type" : "korean",

      "position" : 1

    },

    {

      "token" : "불퉁",

      "start_offset" : 2,

      "end_offset" : 4,

      "type" : "korean",

      "position" : 2

    }

  ]

}


2.x 에서 _analyze 한 결과는 아래와 같습니다.

{

  "tokens" : [ {

    "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" : 2,

    "end_offset" : 4,

    "type" : "korean",

    "position" : 1

  } ]

}


보이시나요?

어디가 다르고 문제가 되는지?


해결 방법은 CompoundNounAnalyzer 의 setDivisibleOne 설정을 false 로 하시면 위와 같은 문제를 해결 하실 수 있습니다.

2.x 에서는 KoreanFilter 쪽에 조건문이 있었는데 5.x 에서는 주석 처리가 되어 있더라구요.

또는 이것 저것 다 귀찮다고 하시면 그냥 '한' 에 대한 불용어 처리를 하셔도 될 것 같습니다.

:

[Elasticsearch] Lucene Arirang Analyzer Plugin for Elasticsearch 5.0.1

Elastic/Elasticsearch 2016. 11. 24. 19:02

우선 빌드한 플러그인 zip 파일 먼저 공유 합니다.

나중에 작업한 내용에 대해서는 github 에 올리도록 하겠습니다.

요즘 프로젝트며 운영 업무가 너무 많아서 이것도 겨우 겨우 시간 내서 작업 했내요.


elasticsearch-analysis-arirang-5.0.1.zip


설치 방법)

$ bin/elasticsearch-plugin install --verbose file:///elasticsearch-analysis-arirang/target/elasticsearch-analysis-arirang-5.0.1.zip


설치 로그)

-> Downloading file:///elasticsearch-analysis-arirang-5.0.1.zip

Retrieving zip from file:///elasticsearch-analysis-arirang-5.0.1.zip

[=================================================] 100%

- Plugin information:

Name: analysis-arirang

Description: Arirang plugin

Version: 5.0.1

 * Classname: org.elasticsearch.plugin.analysis.arirang.AnalysisArirangPlugin

-> Installed analysis-arirang


Elasticsearch 실행 로그)

$ bin/elasticsearch

[2016-11-24T18:49:09,922][INFO ][o.e.n.Node               ] [] initializing ...

[2016-11-24T18:49:10,083][INFO ][o.e.e.NodeEnvironment    ] [aDGu2B9] using [1] data paths, mounts [[/ (/dev/disk1)]], net usable_space [733.1gb], net total_space [930.3gb], spins? [unknown], types [hfs]

[2016-11-24T18:49:10,084][INFO ][o.e.e.NodeEnvironment    ] [aDGu2B9] heap size [1.9gb], compressed ordinary object pointers [true]

[2016-11-24T18:49:10,085][INFO ][o.e.n.Node               ] [aDGu2B9] node name [aDGu2B9] derived from node ID; set [node.name] to override

[2016-11-24T18:49:10,087][INFO ][o.e.n.Node               ] [aDGu2B9] version[5.0.1], pid[56878], build[080bb47/2016-11-11T22:08:49.812Z], OS[Mac OS X/10.12.1/x86_64], JVM[Oracle Corporation/Java HotSpot(TM) 64-Bit Server VM/1.8.0_72/25.72-b15]

[2016-11-24T18:49:11,335][INFO ][o.e.p.PluginsService     ] [aDGu2B9] loaded module [aggs-matrix-stats]

[2016-11-24T18:49:11,335][INFO ][o.e.p.PluginsService     ] [aDGu2B9] loaded module [ingest-common]

[2016-11-24T18:49:11,335][INFO ][o.e.p.PluginsService     ] [aDGu2B9] loaded module [lang-expression]

[2016-11-24T18:49:11,335][INFO ][o.e.p.PluginsService     ] [aDGu2B9] loaded module [lang-groovy]

[2016-11-24T18:49:11,335][INFO ][o.e.p.PluginsService     ] [aDGu2B9] loaded module [lang-mustache]

[2016-11-24T18:49:11,336][INFO ][o.e.p.PluginsService     ] [aDGu2B9] loaded module [lang-painless]

[2016-11-24T18:49:11,336][INFO ][o.e.p.PluginsService     ] [aDGu2B9] loaded module [percolator]

[2016-11-24T18:49:11,336][INFO ][o.e.p.PluginsService     ] [aDGu2B9] loaded module [reindex]

[2016-11-24T18:49:11,336][INFO ][o.e.p.PluginsService     ] [aDGu2B9] loaded module [transport-netty3]

[2016-11-24T18:49:11,336][INFO ][o.e.p.PluginsService     ] [aDGu2B9] loaded module [transport-netty4]

[2016-11-24T18:49:11,336][INFO ][o.e.p.PluginsService     ] [aDGu2B9] loaded plugin [analysis-arirang]

[2016-11-24T18:49:14,151][INFO ][o.e.n.Node               ] [aDGu2B9] initialized

[2016-11-24T18:49:14,151][INFO ][o.e.n.Node               ] [aDGu2B9] starting ...

[2016-11-24T18:49:14,377][INFO ][o.e.t.TransportService   ] [aDGu2B9] publish_address {127.0.0.1:9300}, bound_addresses {[fe80::1]:9300}, {[::1]:9300}, {127.0.0.1:9300}

[2016-11-24T18:49:17,511][INFO ][o.e.c.s.ClusterService   ] [aDGu2B9] new_master {aDGu2B9}{aDGu2B9mQ8KkWCe3fnqeMw}{_y9RzyKGSvqYAFcv99HBXg}{127.0.0.1}{127.0.0.1:9300}, reason: zen-disco-elected-as-master ([0] nodes joined)

[2016-11-24T18:49:17,584][INFO ][o.e.g.GatewayService     ] [aDGu2B9] recovered [0] indices into cluster_state

[2016-11-24T18:49:17,588][INFO ][o.e.h.HttpServer         ] [aDGu2B9] publish_address {127.0.0.1:9200}, bound_addresses {[fe80::1]:9200}, {[::1]:9200}, {127.0.0.1:9200}

[2016-11-24T18:49:17,588][INFO ][o.e.n.Node               ] [aDGu2B9] started


한글형태소분석 실행)

$ curl -X POST -H "Cache-Control: no-cache" -H "Postman-Token: 6d392d83-5816-71ad-556b-5cd6f92af634" -d '{

  "analyzer" : "arirang_analyzer",

  "text" : "[한국] 엘라스틱서치 사용자 그룹의 HENRY 입니다."

}' "http://localhost:9200/_analyze"


형태소분석 결과)

{

  "tokens": [

    {

      "token": "[",

      "start_offset": 0,

      "end_offset": 1,

      "type": "symbol",

      "position": 0

    },

    {

      "token": "한국",

      "start_offset": 1,

      "end_offset": 3,

      "type": "korean",

      "position": 1

    },

    {

      "token": "]",

      "start_offset": 3,

      "end_offset": 4,

      "type": "symbol",

      "position": 2

    },

    {

      "token": "엘라스틱서치",

      "start_offset": 5,

      "end_offset": 11,

      "type": "korean",

      "position": 3

    },

    {

      "token": "엘라",

      "start_offset": 5,

      "end_offset": 7,

      "type": "korean",

      "position": 3

    },

    {

      "token": "스틱",

      "start_offset": 7,

      "end_offset": 9,

      "type": "korean",

      "position": 4

    },

    {

      "token": "서치",

      "start_offset": 9,

      "end_offset": 11,

      "type": "korean",

      "position": 5

    },

    {

      "token": "사용자",

      "start_offset": 12,

      "end_offset": 15,

      "type": "korean",

      "position": 6

    },

    {

      "token": "그룹",

      "start_offset": 16,

      "end_offset": 18,

      "type": "korean",

      "position": 7

    },

    {

      "token": "henry",

      "start_offset": 20,

      "end_offset": 25,

      "type": "word",

      "position": 8

    },

    {

      "token": "입니다",

      "start_offset": 26,

      "end_offset": 29,

      "type": "korean",

      "position": 9

    }

  ]

}


:

[Elasticsearch] BoolQueryBuilder + TermsQueryBuilder 사용 시 minimum_should_match와 min_should_match

Elastic/Elasticsearch 2016. 5. 24. 18:11

이게 또 언제 변수명이 바뀌었을까요?

버전 릴리즈 될때마다 소스코드를 다 따라 갈수가 없다 보니 이런 오류를 경험하게 되내요.


주의) min_should_match 는 java api 를 이용해서는 사용 할 수 없습니다.


[Terms Query]

이 쿼리는 field 에 여러개의 term 을 넣어서 질의 할 수 있도록 해줍니다.

그래서 기본 or 검색을 지원하고 있구요. 여기서 and 연산을 하고 싶으면 terms query 에 아래 변수 값을 지정 하셔야 합니다.


min_should_match:TERM_SIZE


OR)

curl -XGET "http://localhost:9200/_search?pretty" -d'

{

    "size": 10,

    "query" : {

        "terms": {

           "title": [

              "포니",

              "이펙트"

           ],

           "min_should_match": 1

        }                

    }

}'



AND)

curl -XGET "http://localhost:9200/_search?pretty" -d'

{

    "size": 10,

    "query" : {

        "terms": {

           "title": [

              "포니",

              "이펙트"

           ],

           "min_should_match": 2

        }                

    }

}'


[Bool Query + Terms Query]

이 쿼리는 compound query 작성을 위해 많이 사용하는 것입니다.

bool query 안에 terms query 를 섞어 사용하는 것이구요. 좀 더 and, or 연산을 다양하게 할 수 있게 해줍니다.

여기서는 miminum_should_match 를 통해서 and, or 연산을 해야 하는데 terms query 에서의 min_should_match 를 사용하지 않게 되면 정상적인 결과를 얻을 수 없게 됩니다. (아무래도 2.3.3 에서 5.0 으로 넘어가는 과도기라 그런게 아닌가 싶습니다.)

should 를 여러개 사용할 경우 miminum_should_match 설정을 하셔야 합니다.


OR)

curl -XGET "http://localhost:9200/_search?pretty" -d'

{

    "size": 10,

    "query" : {

        "bool" : {

            "should": [

               {

                   "terms": {

                      "title": [

                         "포니",

                         "이펙트"

                      ],

                      "min_should_match": "1"

                   }

               }

            ]

        }

    }

}'


AND)

curl -XGET "http://localhost:9200/_search?pretty" -d'

{

    "size": 10,

    "query" : {

        "bool" : {

            "should": [

               {

                   "terms": {

                      "title": [

                         "포니",

                         "이펙트"

                      ],

                      "min_should_match": "2"

                   }

               }

            ]

        }

    }

}'


:

[Elasticsearch] This Week in Elasticsearch and Apache Lucene - 2016-04-25

Elastic/Elasticsearch 2016. 4. 26. 15:48

이번 weekly 에서 눈에 확 들어 오는건 개인적으로 아래 두 가지 입니다.





원본 글)

https://www.elastic.co/blog/this-week-in-elasticsearch-and-apache-lucene-2016-04-25


Elasticsearch Core

Changes in 2.x:


Changes in master:


Ongoing changes:


: