2015-06-19 30 views
3

我一直在使用不同類型的標記器進行測試和演示。我需要檢查一個特定的文本字段是如何使用不同的標記器進行標記的,並且還可以查看生成的標記。如何檢查爲Elasticsearch中的不同標記器生成的標記

我該如何做到這一點?

+0

你可以安裝查詢插件並測試它:https://github.com/polyfractal/elasticsearch-inquisitor –

回答

3

除了什麼@val所提到的,你可以嘗試一下term vecto R,如果你正打算學習tokenisers.You的工作可以嘗試這樣的事情只是爲了檢驗在斷詞在外地發生

GET /index-name/type-name/doc-id/_termvector?fields=field-to-be-examined 

要知道更多關於tokenisers和他們的操作離子你可以參考這個blog

5

您可以使用_analyze endpoint來實現此目的。

例如,使用標準分析器,可以分析this is a test這樣

curl -XGET 'localhost:9200/_analyze?analyzer=standard&pretty' -d 'this is a test' 

而這將產生以下令牌:

{ 
    "tokens" : [ { 
    "token" : "this", 
    "start_offset" : 0, 
    "end_offset" : 4, 
    "type" : "<ALPHANUM>", 
    "position" : 1 
    }, { 
    "token" : "is", 
    "start_offset" : 5, 
    "end_offset" : 7, 
    "type" : "<ALPHANUM>", 
    "position" : 2 
    }, { 
    "token" : "a", 
    "start_offset" : 8, 
    "end_offset" : 9, 
    "type" : "<ALPHANUM>", 
    "position" : 3 
    }, { 
    "token" : "test", 
    "start_offset" : 10, 
    "end_offset" : 14, 
    "type" : "<ALPHANUM>", 
    "position" : 4 
    } ] 
} 

當然,你可以使用任何existing analyzers和您還可以使用tokenizer參數指定令牌處理器,使用token_filters參數的令牌過濾器以及使用char_filters參數的字符過濾器。例如,使用標準的分析儀,keyword標記生成器,該lowercase令牌過濾器和html_strip字符過濾器的產量分析HTML curl -XGET 'localhost:9200/_analyze?tokenizer=keyword&token_filters=lowercase&char_filters=html_strip' -d 'THIS is a <b>TEST</b>'這一點,即小寫的單個令牌沒有HTML標記:

curl -XGET 'localhost:9200/_analyze?tokenizer=keyword&token_filters=lowercase&char_filters=html_strip' -d 'THIS is a <b>TEST</b>' 

{ 
    "tokens" : [ { 
    "token" : "this is a test", 
    "start_offset" : 0, 
    "end_offset" : 21, 
    "type" : "word", 
    "position" : 1 
    } ] 
} 
+0

注意:你也可以使用'text'查詢參數而不是提交字符串在'-d'的正文中。 – joelittlejohn

相關問題