2017-02-02 28 views
0

ここdefiniton:アポストロフィを取り除く方法は?

アポストロフィトークンフィルタは、アポストロフィの後にアポストロフィ自体を含む をすべての文字が削除されます。

アポストロフィとその後の文字を削除しようとしています。アポストロフィが1つしかない場合、フィルタは何も除去しません。また、連続した複数のアポストロフィがある場合は、関連する単語を分割します。アポストロフィの後には何も削除しません。明らかに私は何かを欠いているに違いない。単一アポストロフィと

入力:複数の連続アポストロフィと

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 
     } ] 
    } ] 
    } 
} 
関連する問題