Substituting Match Phrase Prefix Query with a MUST combination of Match Phrase and Prefix

Hi,

I am using match phrase prefix for suggestion and querying search result. I'm using this for searching employee name, skill name, etc... basically name / title field which is not long.
When I'm searching name like "john d", I'm expecting results such as ["John Doe", "John Dwayne McKinsey", ...] but no results due to the limitation of max_expansions.

Match phrase prefix is as the name suggest, the combination of match phrase and prefix. Hence I'm wondering if I can substitute the query with below snippet.
2 words - 'john d'

{
  query: {
    bool: {
      must: [
        {
          match_phrase: { name: 'john' },
        },
        {
          prefix: { name: 'd' },
        }
      ]
    }
  }
}

3 words - 'john dwayne m'

{
  query: {
    bool: {
      must: [
        {
          match_phrase: { name: 'john dwayne' },
        },
        {
          prefix: { name: 'm' },
        }
      ]
    }
  }
}

or if there's only one word, only prefix is used

{
  query: {
    bool: {
      must: [
        {
          prefix: { name: 'joh' },
        }
      ]
    }
  }
}

I need opinion on above substitute query and whether it will have hidden issue or not?

To note:
This works on my case where the terms/words order is somewhat unimportant. As far as I observe, the response time between match_phrase_prefix and above query are no different.

Thank you

Hi @aliyanamu,

Welcome to the community! From the documentation the last term of the provided text is treated as a prefix. So your examples above would behave equivalently.

Have you tried running your queries through the Search Profiler to look at the differences?

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