2017-08-01 61 views
0

我有一个搜索查询,在输入完整的单词后进行基本搜索。我正在查找3个字母后的自动建议。 例如, 标题 - samsung galaxy s4 我想看到“sam”之后的自动建议,而不是完整的单词“samsung”。3个字母后的弹性搜索中的自动建议

+0

是文档此为web应用程序,我们并不清楚你的问题的web应用的背景下,一个MobileApp –

+0

它应该工作两个Web应用程序和一个MobileApp。我的后端在node.js + express中。 – Jyothi

+0

您可以在客户端处理它,只在输入的字符超过3个字符(不包括空格)时才进行api调用 –

回答

0

您需要为此使用edgeNGram过滤器。

{ 
    "analysis": { 
    "tokenizer": { 
     "autocomplete_tokenizer": { 
      "type": "edgeNGram", 
      "min_gram": "3", 
      "max_gram": "20" 
     } 
    }, 
    "analyzer": { 
     "autocomplete_edge_ngram": { 
      "filter": ["lowercase"], 
      "type": "custom", 
      "tokenizer": "autocomplete_tokenizer" 
     } 
    } 
    } 
} 

和映射将

{ 
    "title_edge_ngram": { 
     "type": "text", 
     "analyzer": "autocomplete_edge_ngram", 
     "search_analyzer": "standard" 
    } 

或者你可以在elasticsearch使用completion suggester。 对于三个字符检查,你必须在你的客户端自己做。