# How to query n-gram completions that match phrase prefix?

**URL:** <https://discuss.elastic.co/t/how-to-query-n-gram-completions-that-match-phrase-prefix/276607>\
**Category:** Elasticsearch\
**Created:** [June 22, 2021, 6:23am UTC](https://discuss.elastic.co/t/how-to-query-n-gram-completions-that-match-phrase-prefix/276607 "2021-06-22T06:23:56Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![sabetai](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/sabetai/32/82900_2.png) [@sabetai](https://discuss.elastic.co/u/sabetai)\
**Post date:** [June 22, 2021, 6:23am UTC](https://discuss.elastic.co/t/how-to-query-n-gram-completions-that-match-phrase-prefix/276607/1 "2021-06-22T06:23:56Z")

</div>

How can I query my index to suggest phrases that complete the user's query? I'd like a query similar to `match_phrase_prefix` , except instead of retrieving the entire doc it returns n-grams from the doc fields that completes the phrase?

None of the suggesters seem to fit my use-case, where `completion suggester` requires that suggestions be indexed explicity, and `phrase suggester` seems to suggest spelling error fixes instead of phrase completions.

---

<div class="post-metadata">

**Author:** ![spinscale](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/spinscale/32/25011_2.png) [@spinscale](https://discuss.elastic.co/u/spinscale)\
**Post date:** [June 22, 2021, 7:48am UTC](https://discuss.elastic.co/t/how-to-query-n-gram-completions-that-match-phrase-prefix/276607/2 "2021-06-22T07:48:23Z")

</div>

can you share a reproducible example, including index/mapping/query and what does not work as you expect it to be, so other can follow your example better? Thanks!

---

<div class="post-metadata">

**Author:** ![sabetai](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/sabetai/32/82900_2.png) [@sabetai](https://discuss.elastic.co/u/sabetai)\
**Post date:** [June 22, 2021, 3:17pm UTC](https://discuss.elastic.co/t/how-to-query-n-gram-completions-that-match-phrase-prefix/276607/3 "2021-06-22T15:17:02Z")

</div>

More precisely, I want the same functionality as `search_as_you_type` ([example](https://www.elastic.co/guide/en/elasticsearch/reference/current/search-as-you-type.html)), except with word n-gram results, instead of retrieving the entire `_source`. For example, if the `_source` in the `search_as_you_type` field is "quick brown fox jump lazy dog", and my query is "brown f", then the result should be "brown fox", or "quick brown fox", not "quick brown fox jump lazy dog".

Also, I'd like to achieve this without additional indexing ie explicitly add `suggest` entries as with the `completion` suggester.

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [July 20, 2021, 3:17pm UTC](https://discuss.elastic.co/t/how-to-query-n-gram-completions-that-match-phrase-prefix/276607/4 "2021-07-20T15:17:07Z")

</div>

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.
