# How to use minimum\_should\_match for prefix search?

**URL:** <https://discuss.elastic.co/t/how-to-use-minimum-should-match-for-prefix-search/352363>\
**Category:** Elasticsearch\
**Created:** [February 2, 2024, 7:07am UTC](https://discuss.elastic.co/t/how-to-use-minimum-should-match-for-prefix-search/352363 "2024-02-02T07:07:29Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Leonid\_P](https://avatars.discourse-cdn.com/v4/letter/l/e99b99/32.png) [@Leonid\_P](https://discuss.elastic.co/u/Leonid_P)\
**Post date:** [February 2, 2024, 7:07am UTC](https://discuss.elastic.co/t/how-to-use-minimum-should-match-for-prefix-search/352363/1 "2024-02-02T07:07:29Z")

</div>

I want to make a search-as-you-type search service (with tokenization, analyzer etc.) and to use `minimum_should_match` in it, i.e. to show pages with three of four typed tokens but not with two of four.

What is the best way to do it?

One that I see is to add \* to the text typed (to make it work as a prefix search) and to wrap it into `simple_query_string` or `query_string`, but this approach has obvious disadvantages, for example these types of queries take into account all wildcard symbols (- " etc.) which is often inconvenient.

---

<div class="post-metadata">

**Author:** ![Christian\_Dahlqvist](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/christian_dahlqvist/32/4617_2.png) [@Christian\_Dahlqvist](https://discuss.elastic.co/u/Christian_Dahlqvist)\
**Post date:** [February 12, 2024, 7:38am UTC](https://discuss.elastic.co/t/how-to-use-minimum-should-match-for-prefix-search/352363/2 "2024-02-12T07:38:10Z")

</div>

Have you looked into using an analyzer with an [edge ngram filter](https://www.elastic.co/guide/en/elasticsearch/reference/8.12/analysis-edgengram-tokenfilter.html)? You could set `min_gram` to 3 to avoid matching on short strings.

---

<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:** [March 11, 2024, 7:38am UTC](https://discuss.elastic.co/t/how-to-use-minimum-should-match-for-prefix-search/352363/3 "2024-03-11T07:38:32Z")

</div>

Closed on March 11, 2024, 7:38am UTC

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