How to use max_expansions in elasticsearch full-text search match_phrase_prefix query?

first of all, I am using elasticsearch 6.3.The following is a description of the problem:

the official document says that there is a parameter max_expansions in the match_phrase_prefix query that says that the parameter max_expansions controls the number of words that can match the prefix, with a default value of 50.

take the I like swi query as an example, which first looks for the first word that matches the prefix swi , and then searches and collects the matching words in alphabetical order until there are no more matching words or when the number exceeds max_expansions.

but when I use it, I deliberately invent dozens of words that start with swi and set the value of max_expansions to 10. But it returns all the results. If you know why, please let me know. Thank you very much.

GET matchphaseprefixtest/_search
{
  "query": {
    "match_phrase_prefix": {
      "message": {
        "query": "I like sw",
        "max_expansions": 10
       }
    }
  }
}

< del > your queryDSL is written as match , changed to match_phrase_prefix < / del >

< hr >

How to Use Fuzzy Searches in Elasticsearch there is a passage in this blog

It is important to understand that the max_expansions query limit works at the shard level, meaning that even if set to 1, multiple terms may match, all coming from different shards. This behavior can make it seem as if max_expansions is not in effect, so beware that counting unique terms that come are returned is not a valid way to determine if max_expansions is working.
The main idea of

is that max_expansions acts at the fragment level (shard level) , which means that even if set to 1, it is still possible to match multiple words from different fragment (shards) . This behavior makes the results look as if max_expansions doesn't work, so keep in mind that calculating the number of keywords returned by search results cannot be used as a way to verify whether max_expansions is valid

.

the blog is about fuzzy query, but the test results show that this parameter works the same way in match phrase prefix query

< H2 > verify < / H2 >

validate by specifying routing so that the results all come from one shard, but it is important to note that the shard has only part of the document unless you all specify the same routing when indexing the document

GET matchphaseprefixtest/_search?routing=1
{
  "query": {
    "match_phrase_prefix": {
      "message": {
        "query": "I like sw",
        "max_expansions": 10
       }
    }
  }
}
MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1c273c2-3383a.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1c273c2-3383a.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?