10

I'm specifying a fuzzy_prefix_length in the query string, but a search for "tes" is not pulling up posts that are titled "test" ... any ideas what I'm doing wrong?

this is my query string setup

"query" : {
  "query_string" : {
    "query" : the-query-string-goes-here,
    "default_operator" : "AND",
    "fuzzy_prefix_length" : 3,
  }
}

1 Answer 1

13

You are, probably, missing "fuzzy" operator at the end of the query. Try this:

"query" : {
  "query_string" : {
    "query" : "tes~",
    "default_operator" : "AND",
    "fuzzy_prefix_length" : 3,
  }
}
Sign up to request clarification or add additional context in comments.

2 Comments

Ahh I see ... couple of questions if you don't mind ... I've heard wildcard queries are slower than average and don't scale. Any similar concerns with this operator? Also, right now a search for "tes" will pull up a post titled "test" but a search for "est" won't ... is there a way to make it do this ... or am I overreaching?
"est" doesn't return any results because you specified non-zero fuzzy_prefix_length. The fuzzy_prefix_length sets the number of characters at the beginning of the term that have to match. Zero fuzzy_prefix_length would require elasticsearch to fuzzy match all terms in the dictionary to the term in your query. By specifying non-zero fuzzy_prefix_length, you can significantly limit the number of terms to check and improve performance. As you mentioned, it's somewhat similar to the wild card queries, except the term matching algorithm is more sophisticated in case of fuzzy operator.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.