It's because of the max_expansions value. By default it's set to 50. So when you send query with longer characters (eg. "202201") you will see the results. You can increase the max_expansion value the but it can hurt the performance.
See my screenshot, both queries are showing the results because I have only one doc in test index.
See the notes from official documentation: Match phrase prefix query | Elasticsearch Guide [8.14] | Elastic
As a workaround you can choose one of the followings.
- Increase the
max_expansionvalue in your query. - Use edge_ngram tokenizer - This will also tune the query speed. (recommended)
- Use prefix query - there is no
max_expansionlimit for the prefix query but it can be slower thanphrase_prefix.
