2014-01-29 49 views
4

我使用Suggest API爲餐廳名稱創建自動完成,但我遇到了一個小問題。一些餐館的名字以數字開頭,例如:Elasticsearch建議API - 不要搜索數字

68 - 86 Bar & Restaurant 

我希望能夠輸入68,並獲得餐廳回來。我試過使用空白分析器,但它不能解決我的問題。

下面是餐廳名稱解析輸出:

{ 
    "tokens": [ 
    { 
     "token": "68", 
     "start_offset": 0, 
     "end_offset": 2, 
     "type": "<NUM>", 
     "position": 1 
    }, 
    { 
     "token": "86", 
     "start_offset": 5, 
     "end_offset": 7, 
     "type": "<NUM>", 
     "position": 2 
    }, 
    { 
     "token": "bar", 
     "start_offset": 8, 
     "end_offset": 11, 
     "type": "<ALPHANUM>", 
     "position": 3 
    }, 
    { 
     "token": "restaurant", 
     "start_offset": 14, 
     "end_offset": 24, 
     "type": "<ALPHANUM>", 
     "position": 4 
    } 
    ] 
} 

這裏是重現我的問題的命令:

PUT restaurants 
{ } 

PUT restaurants/restaurant/_mapping 
{ 
    "location": { 
     "index_analyzer": "whitespace", 
     "search_analyzer": "whitespace", 
     "properties": { 
      "name_suggest": { 
       "type": "completion", 
       "payloads": true 
      } 
     } 
    } 
} 

POST restaurants/restaurant/1 
{ 
    "name_suggest": { 
     "input": [ 
      "68 - 86 Bar & Restaurant" 
     ], 
     "output": "68 - 86 Bar & Restaurant", 
     "payload": { 
      "id": 1067 
     } 
    } 
} 

POST restaurants/_suggest 
{ 
    "suggestions": { 
     "text": "68 - 86", 
     "completion": { 
      "field": "name_suggest" 
     } 
    } 
} 

我沒有得到來自_suggest任何結果。任何幫助,將不勝感激。

回答

5

我解決了它,真的很簡單,但也許是一個錯誤?

相反的:

PUT restaurants/restaurant/_mapping 
{ 
    "location": { 
     "index_analyzer": "whitespace", 
     "search_analyzer": "whitespace", 
     "properties": { 
      "name_suggest": { 
       "type": "completion", 
       "payloads": true 
      } 
     } 
    } 
} 

我現在有:

PUT restaurants/restaurant/_mapping 
{ 
    "location": { 
     "properties": { 
      "name_suggest": { 
       "type": "completion", 
       "index_analyzer": "whitespace", 
       "search_analyzer": "whitespace", 
       "payloads": true 
      } 
     } 
    } 
} 
+1

過這個問題剛剛來到自己,看似簡單分析器不換號工作...謝謝你的分享! – sourcx

+0

不錯,有同樣的問題 – chris