Alex B
Alex B

Reputation: 73

Elasticsearch phrase prefix results

I have two ES queries:

{match:{text:{query: "text box", type: "phrase"}}}
{match:{text:{query: "text bo", type: "phrase_prefix"}}}

The problem is that the second query returns fewer documents than the first one, although I would expect the second query to return all records from the first one plus something extra. What am I missing?

Thanks

Upvotes: 1

Views: 1630

Answers (1)

ChintanShah25
ChintanShah25

Reputation: 12672

This could be due to max_expansions being set to its default value 10

Try this

{
  "query": {
    "match_phrase_prefix": {
      "text": {
        "query": "text bo",
        "max_expansions": 100
      }
    }
  }
}

This thread will help you understand how terms are expanded. make max_expansions 1000 and see the results.

Basically you have lot of words starting with bo like bond, boss and since 'x' comes last alphabetically, you are not getting what you expect.

I hope this helps!

Upvotes: 2

Related Questions