2014-01-29 50 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