2016-04-30 87 views
2

我正在使用Elasticsearch構建一個小型搜索應用程序,並試圖找出如何使用多詞(短語)建議來構建自動完成功能。我有它的工作...有點...如何生成多詞搜索建議

我主要是單個單詞的建議,但是當我點擊空格鍵 - 它殺死的建議。

例如,如果我輸入「fast」,它會正常工作,如果我輸入「fast」 - 停止出現建議。

我使用的是Edge N Gramsmatch_phrase_prefix,並按照示例herehere構建它。對於match_phrase_prefix中的_all字段,只是使用include_in_all:false來取消除標題和內容以外的所有字段。我開始認爲它僅僅是因爲我正在測試一個小數據集,並且沒有足夠的標記術語來產生多詞建議。請看下面的相關代碼,並告訴我哪裏出錯了,如果有的話?

"analysis": { 
"filter": { 
"autocomplete_filter": { 
    "type": "edge_ngram", 
    "min_gram": "1", 
    "max_gram": "20", 
    "token_chars": [ 
    "letter", 
    "digit" 
    ] 
} 
}, 
"analyzer": { 
    "autocomplete": { 
    "type": "custom", 
    "tokenizer": "whitespace", 
    "filter": [ 
     "lowercase", 
     "asciifolding", 
     "autocomplete_filter" 
    ]  
    }, 
    "whitespace_analyzer": { 
    "type": "custom", 
    "tokenizer": "whitespace", 
    "filter": [ 
     "lowercase", 
     "asciifolding" 
     ] 

回答

0

嘗試keyword標記者

"autocomplete": { 
    "type": "custom", 
      "filter": [ 
     "lowercase", 
     "asciifolding", 
     "autocomplete_filter" 
    ], 
"tokenizer": "keyword"  
    } 

參考 elasticsearch mapping tokenizer keyword to avoid splitting tokens and enable use of wildcard

因爲默認情況下它的標準anaylyzer上空間 您可以檢查您的令牌一樣curl 'localhost:9200/test/_analyze?pretty=1&analyzer=my_edge_ngram_analyzer' -d 'FC Schalke 04'參考https://www.elastic.co/guide/en/elasticsearch/reference/current/analysis-edgengram-tokenizer.html

+0

感謝似乎分裂正是我所期待的 – user3125823