elasticsearch-analysis-openkoreantext icon indicating copy to clipboard operation
elasticsearch-analysis-openkoreantext copied to clipboard

array 형태의 텍스트 입력시 나오는 토큰의 오프셋 질문 드립니다.

Open GardeningYoon opened this issue 6 years ago • 10 comments

안녕하세요, open-korean-text를 사용하여 ES에 데이터 인덱싱을 하려고하는데, array 형태의 데이터 입력시 offset 문제로 인덱싱이 되지 않아 질문 드립니다.

인덱싱 할 텍스트가 ["동해물과 백두산이", "마르고 닳도록"] 위와 같은 형태일 경우

open-korean-text 사용시 생기는 토큰의 오프셋은 인덱스가 바뀔 때 마다 초기화가 되고, ES에서 제공하는 기본 analyzer 사용시에는 array내의 모든 string이 순서대로 오프셋이 정해지는데요,

ES에 데이터를 인덱싱 할 경우 한 필드 내에서는 offest이 다시 뒤로가는 경우가 생기면 인덱싱이 되지 않으며 warning이 발생합니다.

이 이슈 수정 요청 드려도 될까요? 분석결과는 아래 참고 부탁드립니다.

open-korean-text 사용시

{
  "tokens" : [
    {
      "token" : "동",
      "start_offset" : 0,
      "end_offset" : 1,
      "type" : "Modifier",
      "position" : 0
    },
    {
      "token" : "해물",
      "start_offset" : 1,
      "end_offset" : 3,
      "type" : "Noun",
      "position" : 1
    },
    {
      "token" : "백두산",
      "start_offset" : 5,
      "end_offset" : 8,
      "type" : "Noun",
      "position" : 2
    },
    {
      "token" : "마르고",
      "start_offset" : 1,
      "end_offset" : 4,
      "type" : "Noun",
      "position" : 103
    },
    {
      "token" : "닳다",
      "start_offset" : 5,
      "end_offset" : 8,
      "type" : "Verb",
      "position" : 104
    }
  ]
}

ES에서 제공하는 기본 analyzer 사용시

{
  "tokens" : [
    {
      "token" : "동해물과",
      "start_offset" : 0,
      "end_offset" : 4,
      "type" : "<HANGUL>",
      "position" : 0
    },
    {
      "token" : "백두산이",
      "start_offset" : 5,
      "end_offset" : 9,
      "type" : "<HANGUL>",
      "position" : 1
    },
    {
      "token" : "마르고",
      "start_offset" : 10,
      "end_offset" : 13,
      "type" : "<HANGUL>",
      "position" : 102
    },
    {
      "token" : "닳도록",
      "start_offset" : 14,
      "end_offset" : 17,
      "type" : "<HANGUL>",
      "position" : 103
    }
  ]
}

GardeningYoon avatar Jan 16 '18 06:01 GardeningYoon

이슈 남겨주셔서 감사합니다. 해당 문제에 대해서 대략적으로 이해했지만, 자세하게 이해하진 못했는데요.

혹시 테스트 케이스를 작성해서 PR로 올려주시면 더 확인하기 쉽겠지만, 번거로우시다면 정확하게 어떤 부분이 문제인지, 실제로 기대 결과는 무엇인지 알려주세요.

감사합니다.

keepcosmos avatar Jan 16 '18 08:01 keepcosmos

analyzer가 어떤 식으로 array 형태의 입력을 받는지는 몰라 확인 후 테스트 케이스 작성해서 리퀘스트 올리도록 하겠습니다.

우선 문제부분과 기대결과를 말씀드리면,

기본 분석기를 사용하는 필드와 openkoreantext-analyzer를 사용하는 필드 생성후 각 필드에 array형태의 데이터를 입력 할 경우 기본 분석기를 사용하는 필드는 정상적으로 인덱싱 되어 데이터가 들어가고, openkoreantext-analyzer를 사용하는 필드는 데이터 추가가 되지 않습니다.

기대 결과는 문자열이 array 형태로 들어가게 되는 경우에도 정상적으로 데이터가 추가 되는것입니다.

아래에 인덱스 생성, 도큐먼트 생성 & 확인 가능한 curl 예시입니다. openkoreantext-analyzer를 사용한 필드(text_openkorean)에 데이터 입력시 발생하는 에러메시지와, 첫 글에 남겼던 토큰들의 offset들을 봐 주시면 될 것 같습니다.

#인덱스 생성
curl -XPUT 'localhost:9200/test?pretty' -H 'Content-Type: application/json' -d '{
  "mappings": {
    "doc": {
      "properties": {
        "text_basic": {
          "type": "text"
        },
        "text_openkorean": {
          "type": "text", "analyzer":"openkoreantext-analyzer"
        }
      }
    }
  }
}'

# 일반 필드에 데이터 입력
curl -XPUT 'localhost:9200/test/doc/1?pretty&pretty' -H 'Content-Type: application/json' -d'
{
  "text_basic": ["동해물과 백두산이","마르고 닳도록"]
}
'
# 정상적으로 입력 됨
curl -XGET 'localhost:9200/test/doc/1?pretty&pretty'


# openkoreantext-analyzer를 사용하는 필드에 데이터 입력 -> 오류 발생
curl -XPUT 'localhost:9200/test/doc/2?pretty&pretty' -H 'Content-Type: application/json' -d'
{
  "text_openkorean": ["동해물과 백두산이","마르고 닳도록"]
}
'

#입력 된 데이터 없음
curl -XGET 'localhost:9200/test/doc/2?pretty&pretty'

GardeningYoon avatar Jan 17 '18 07:01 GardeningYoon

일단, ES에서 analyzer로 데이터를 보낼 때, array 타입이라고 해서 다른 포멧으로 보내지는 않는걸로 알고 있습니다. 그냥 각 인덱스의 아이템별로 수행할거에요.

현재 ES 5.5.2 버젼에서 테스트해봤는데, 작성해주신 케이스는 정상 입력됩니다. 혹시 사용하시는 버젼과, 오류 발생시 로그를 알려주실 수 있나요?

keepcosmos avatar Jan 17 '18 08:01 keepcosmos

첫번째 작성해주신 예에서는, array의 두번째 인덱스 "마르고"의 start offset이 0이 아닌 1로 표시되는 것이 이슈인거 같은데 맞나요?

keepcosmos avatar Jan 17 '18 08:01 keepcosmos

헛 저도 금방 5.2.2로 받아서 해보니 정상이네요 제가 사용 한 버전은 ES 6.1.2 인데, 버전차이에 따른 동작차이가 있는것같습니다.

ES 내장 분석기의 토큰결과와 비교해볼때는 이전행의 마지막 단어 - "백두산" - 의 start offset : 5 보다 "마르고"의 start offset이 더 커야된다고 생각했는데,

버전별로 동작이 다른 이유를 먼저 알아봐야 할 것 같네요. 변경점 확인 후 관련정보 공유 드리겠습니다.

우선 에러 로그 아래에 전달 드립니다.

> curl -XPUT 'localhost:9200/test/doc/2?pretty&pretty' -H 'Content-Type: application/json' -d'
> {
>   "text_openkorean": ["동해물과 백두산이","마르고 닳도록"]
> }
> '
{
  "error" : {
    "root_cause" : [
      {
        "type" : "illegal_argument_exception",
        "reason" : "startOffset must be non-negative, and endOffset must be >= startOffset, and offsets must not go backwards startOffset=1,endOffset=4,lastStartOffset=5 for field 'text_openkorean'"
      }
    ],
    "type" : "illegal_argument_exception",
    "reason" : "startOffset must be non-negative, and endOffset must be >= startOffset, and offsets must not go backwards startOffset=1,endOffset=4,lastStartOffset=5 for field 'text_openkorean'"
  },
  "status" : 400
}

GardeningYoon avatar Jan 17 '18 10:01 GardeningYoon

저도 비슷한 문제를 경험하고 있습니다. 제 경우는 copy_to로 필드 3개의 내용을 하나의 필드로 모아서 분석기를 거치는데요. 그 중 배열이 없어도 @GardeningYoon 님께서 리포트 하신 문제와 동일한 문제가 발생합니다. 구성 문장이 총 1개일 때는 오류가 안 나고 배열이든 copy_to 필드가 2개 이상 내용이 차 있다거나 하면 문제가 발생합니다. 전 6.1.1 버전입니다.

틈나면 좀 살펴보려고 하고 있습니다. 혹시라도 여기 진전이 있기 전에 진행이 되면 공유하겠습니다.

dynaxis avatar Jan 18 '18 10:01 dynaxis

@GardeningYoon @dynaxis 전체적으로 array 타입으로 데이터가 들어가면 제대로 된 오프셋이 설정되지 않고, 6.1.x 버젼에서는 확실히 에러가 발생하는군요. 해당 문제에 대해 확인해보도록 하겠습니다.

keepcosmos avatar Jan 19 '18 01:01 keepcosmos

저도 비슷한 문제가 발생하네요.. array 형태의 object 에서 발생합니다..

littlehome-eugene avatar Jan 14 '19 14:01 littlehome-eugene

I have the similar issue

raozexiong avatar Feb 11 '20 12:02 raozexiong

Is there any suggestion to fix it.

raozexiong avatar Feb 11 '20 12:02 raozexiong

https://github.com/WilliamVenner/gmpublisher/pull/15/files#diff-849e3fab5f8f13d7147af2a08e45ac75945b75506dae850ca68d942a3c34c142R181-R189

I skipped the translation for these sentences because the tags themselves of the Workshop are not translated to avoid misunderstandings.

but i don't understand the "i use arch btw" on line 170

https://github.com/WilliamVenner/gmpublisher/pull/12#issuecomment-826100417

FlorianLeChat avatar Apr 24 '21 16:04 FlorianLeChat

please stop starting civil wars

WilliamVenner avatar Apr 24 '21 16:04 WilliamVenner

https://github.com/WilliamVenner/gmpublisher/pull/15/files#diff-849e3fab5f8f13d7147af2a08e45ac75945b75506dae850ca68d942a3c34c142R181-R189

I skipped the translation for these sentences because the tags themselves of the Workshop are not translated to avoid misunderstandings.

but i don't understand the "i use arch btw" on line 170

#12 (comment)

I know, I avoided tags such as scenic, fun etc... but some sentences didn't seem good. I just corrected them. As for the tags I translated, they are in the game as well...

please stop starting civil wars

Haha no problem, all cool here :)

Niilyx avatar Apr 24 '21 16:04 Niilyx

please stop starting civil wars

of course it happened under French translation

R4K0 avatar Apr 24 '21 16:04 R4K0