9

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,
  }
}
concept47
  • 30,257
  • 12
  • 52
  • 74

1 Answers1

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,
  }
}
imotov
  • 28,277
  • 3
  • 90
  • 82
  • 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? – concept47 Sep 18 '12 at 08:15
  • 1
    "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. – imotov Sep 18 '12 at 13:25