2017-02-02 10 views
0

은 definiton :아포스트로피 제거 방법 여기

아포스트로피 토큰 필터 스트립을 모든 문자 아포스트로피 자체를 포함하여 아포스트로피, 후.

아포스트로피 및 문자를 제거하려고 시도합니다. 아포스트로피가 하나만있는 경우 필터는 아무 것도 제거하지 않습니다. 또한 여러 개의 연속 된 아포스트로피가있는 경우 관련 단어 을 분할하지만 아포스트로피 뒤에 아무 것도 제거하지 않습니다. 분명히 나는 ​​뭔가를 놓쳤을 것입니다. 단일 아포스트로피와

입력 :

POST localhost:9200/_analyze? 
{ 
    "filter": ["apostrophe"], 
    "text": "apple banana'orange kiwi" 
} 

출력 다수의 연속 아포스트로피

{ 
    "tokens": [ 
    { 
     "token": "apple", 
     "start_offset": 0, 
     "end_offset": 5, 
     "type": "<ALPHANUM>", 
     "position": 0 
    }, 
    { 
     "token": "banana'orange", 
     "start_offset": 6, 
     "end_offset": 19, 
     "type": "<ALPHANUM>", 
     "position": 1 
    }, 
    { 
     "token": "kiwi", 
     "start_offset": 20, 
     "end_offset": 24, 
     "type": "<ALPHANUM>", 
     "position": 2 
    } 
    ] 
} 

입력.

{ 
    "filter": ["apostrophe"], 
    "text": "apple banana''orange kiwi" 
} 

출력

{ 
    "tokens": [ 
    { 
     "token": "apple", 
     "start_offset": 0, 
     "end_offset": 5, 
     "type": "<ALPHANUM>", 
     "position": 0 
    }, 
    { 
     "token": "banana", 
     "start_offset": 6, 
     "end_offset": 12, 
     "type": "<ALPHANUM>", 
     "position": 1 
    }, 
    { 
     "token": "orange", 
     "start_offset": 14, 
     "end_offset": 20, 
     "type": "<ALPHANUM>", 
     "position": 2 
    }, 
    { 
     "token": "kiwi", 
     "start_offset": 21, 
     "end_offset": 25, 
     "type": "<ALPHANUM>", 
     "position": 3 
    } 
    ] 
} 
+0

죄송 합니다만, 아포스트로피를 없애시겠습니까? 또는 그 (것)들에 의하여 나누고 그 (것)들을 제거하십시오? – Mysterion

+0

아포스트로피와 그 뒤에 나오는 문자를 제거하고 싶습니다. 질문을 업데이트했습니다. – gunererd

+0

https://www.elastic.co/guide/en/elasticsearch/reference/current/analysis-pattern-replace-charfilter.html을 시도해보십시오. – Mysterion

답변

1

당신은 혼자가 토큰 필터를 사용하는 standard 분석기는 킥과 토큰 화 입력을하고 apostrophe 토큰 필터가 무시됩니다 때문에 작동하지 않습니다. 당신이 볼 수 있듯이, 위의 단지 standard 분석기를 사용했다

curl -XPOST 'localhost:9200/_analyze?pretty&filter=apostrophe&explain' -d "apple banana'orange kiwi" 
{ 
    "detail" : { 
    "custom_analyzer" : false, 
    "analyzer" : { 
     "name" : "standard", 
     "tokens" : [ { 
     "token" : "apple", 
     "start_offset" : 0, 
     "end_offset" : 5, 
     "type" : "<ALPHANUM>", 
     "position" : 0, 
     "bytes" : "[61 70 70 6c 65]", 
     "positionLength" : 1 
     }, { 
     "token" : "banana'orange", 
     "start_offset" : 6, 
     "end_offset" : 19, 
     "type" : "<ALPHANUM>", 
     "position" : 1, 
     "bytes" : "[62 61 6e 61 6e 61 27 6f 72 61 6e 67 65]", 
     "positionLength" : 1 
     }, { 
     "token" : "kiwi", 
     "start_offset" : 20, 
     "end_offset" : 24, 
     "type" : "<ALPHANUM>", 
     "position" : 2, 
     "bytes" : "[6b 69 77 69]", 
     "positionLength" : 1 
     } ] 
    } 
    } 
} 

: 당신이 explain 매개 변수를 추가하는 경우 당신은 무슨 일이 일어나고 있는지에 대한 자세한 정보를 얻을.

이 문제를 해결하려면 적어도 토큰 화 프로그램을 지정하기 만하면됩니다. standard 토크 나이저를 사용하면 예상대로 작동합니다. 그리고 standard 토크 나이저와 이제 제대로 작동 할 수있는 apostrophe 토큰 필터를 사용하는 맞춤형 분석기가 있음을 알 수 있습니다.

curl -XPOST 'localhost:9200/_analyze?pretty&tokenizer=standard&filter=apostrophe&explain' -d "apple banana'orange kiwi" 
{ 
    "detail" : { 
    "custom_analyzer" : true, 
    "charfilters" : [ ], 
    "tokenizer" : { 
     "name" : "standard", 
     "tokens" : [ { 
     "token" : "apple", 
     "start_offset" : 0, 
     "end_offset" : 5, 
     "type" : "<ALPHANUM>", 
     "position" : 0, 
     "bytes" : "[61 70 70 6c 65]", 
     "positionLength" : 1 
     }, { 
     "token" : "banana'orange", 
     "start_offset" : 6, 
     "end_offset" : 19, 
     "type" : "<ALPHANUM>", 
     "position" : 1, 
     "bytes" : "[62 61 6e 61 6e 61 27 6f 72 61 6e 67 65]", 
     "positionLength" : 1 
     }, { 
     "token" : "kiwi", 
     "start_offset" : 20, 
     "end_offset" : 24, 
     "type" : "<ALPHANUM>", 
     "position" : 2, 
     "bytes" : "[6b 69 77 69]", 
     "positionLength" : 1 
     } ] 
    }, 
    "tokenfilters" : [ { 
     "name" : "apostrophe", 
     "tokens" : [ { 
     "token" : "apple", 
     "start_offset" : 0, 
     "end_offset" : 5, 
     "type" : "<ALPHANUM>", 
     "position" : 0, 
     "bytes" : "[61 70 70 6c 65]", 
     "positionLength" : 1 
     }, { 
     "token" : "banana", 
     "start_offset" : 6, 
     "end_offset" : 19, 
     "type" : "<ALPHANUM>", 
     "position" : 1, 
     "bytes" : "[62 61 6e 61 6e 61]", 
     "positionLength" : 1 
     }, { 
     "token" : "kiwi", 
     "start_offset" : 20, 
     "end_offset" : 24, 
     "type" : "<ALPHANUM>", 
     "position" : 2, 
     "bytes" : "[6b 69 77 69]", 
     "positionLength" : 1 
     } ] 
    } ] 
    } 
}