Why does elasticsearch return inconsistent result on version 7.8.1 and return correct result on 5.6.7 for the same match_phrase_prefix query? How can i get consistent result on elasticsearch 7.8.1?

Match phrase prefix is designed to help auto complete someone typing "Trust f" by perhaps suggesting "Trust fund".
It does this by taking the last word in the string and finding up to N words that begin with those characters and using those N words in combination with the preceding words in the string. The first 5 words in the index that begin with f might be "fab", "fad", "far", "fast", "fat". This would produce searches for the phrases "Trust fab", "Trust fad".... etc
Not very clever because these word pairings may never have been used together. This is why the docs recommend looking at alternatives.

As for why things have changed in your example:
When you search for "Trust" using this query it is expanded into words matching "Trust*" - so words like "trustworthy" and "trustworthiness".

Each of these expanded words are found in the current shard so if you are using 5.6 with default settings of 5 shards each shard will hold one fifth of all the docs so a max_expansion setting of 10 may be enough to discover all "Trust*" words in a small shard.
In 7.x the default is to have a single shard so all docs and all words will be in the same shard. A max_expansion setting of 10 may not be enough to list all the "Trust*" words in this larger index.

It's probably easier to start by describing what business problem you're trying to solve and then we can recommend how best to implement it.

1 Like