0

I'm currently using this ES query for search suggestion from ES (using edge n grams)

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"
      }
    }

Which works but only for single words. As I type letters, single word suggestions appear, but I'm trying to get multi-word suggestions, separated by spaces (phrase suggestions). Is there a better ES query to use so that I can get some phrase suggestions?

user3125823
  • 1,846
  • 2
  • 18
  • 46

1 Answers1

0

Use match_phrase_prefix Query. It will fetch you phrase suggestions: ES Query is like:

 {
 "match_phrase_prefix" : {
    "message" : {
        "query" : "quick brown f"
     }
   }
 } 
Richa
  • 7,419
  • 6
  • 25
  • 34