Elasticsearch查询多词搜索建议

用户名

我目前正在使用此ES查询来查询来自ES的搜索建议(使用n克边)

var terms = query.split(' '),
    baseTerms = terms.length === 1 ? '' : terms.slice(0, -1).join(' ') + ' ',
    lastTerm = terms[terms.length - 1].toLowerCase();

"query": {
      "simple_query_string": {
        "fields": ['title.autocomplete'], //title.basic
        "query": baseTerms + '(' + lastTerm + '|' + lastTerm + '*)',
        "default_operator": "and"
      }
    }

哪个有效,但仅适用于单个单词。当我输入字母时,会出现单个单词建议,但我正在尝试获取多个单词建议,并用空格(短语建议)分隔。是否有更好的ES查询可使用,以便获得一些短语建议?

里查

使用match_phrase_prefix Query它将为您提供短语建议:ES查询类似于:

 {
 "match_phrase_prefix" : {
    "message" : {
        "query" : "quick brown f"
     }
   }
 } 

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章