<p dir="auto">Just something I stumpled upon and I am not sure if this is a potential bug.</p>
<p dir="auto">In the MatchQuery class in the blendTermQuery method there is</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="    if (fuzziness != null) {
        if (mapper != null) {
            Query query = mapper.fuzzyQuery(term.text(), fuzziness, fuzzyPrefixLength, maxExpansions, transpositions);
            if (query instanceof FuzzyQuery) {
                QueryParsers.setRewriteMethod((FuzzyQuery) query, fuzzyRewriteMethod);
            }
        }
        int edits = fuzziness.asDistance(term.text());
        FuzzyQuery query = new FuzzyQuery(term, edits, fuzzyPrefixLength, maxExpansions, transpositions);
        QueryParsers.setRewriteMethod(query, rewriteMethod);
        return query;
    }"><pre class="notranslate"><code class="notranslate">    if (fuzziness != null) {
        if (mapper != null) {
            Query query = mapper.fuzzyQuery(term.text(), fuzziness, fuzzyPrefixLength, maxExpansions, transpositions);
            if (query instanceof FuzzyQuery) {
                QueryParsers.setRewriteMethod((FuzzyQuery) query, fuzzyRewriteMethod);
            }
        }
        int edits = fuzziness.asDistance(term.text());
        FuzzyQuery query = new FuzzyQuery(term, edits, fuzzyPrefixLength, maxExpansions, transpositions);
        QueryParsers.setRewriteMethod(query, rewriteMethod);
        return query;
    }
</code></pre></div>
<p dir="auto">As far as I can see the if (mapper != null) branch doesn't really do anything. Shouldn't that Query be returned?</p>
<p dir="auto">There are various bugs to do with <code class="notranslate">match</code> query rewriting.</p>
<h2 dir="auto">Wrong <code class="notranslate">fuzzy_rewrite</code> default</h2>
<p dir="auto">The docs for the <a href="http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/query-dsl-match-query.html#_boolean" rel="nofollow">boolean match query</a> say that fuzziness should use a <code class="notranslate">constant_score</code> rewrite method by default.  Instead it uses the <code class="notranslate">top_terms_N</code> method.</p>
<h2 dir="auto"><code class="notranslate">fuzzy_rewrite</code> never applied</h2>
<p dir="auto">The <code class="notranslate">fuzzy_rewrite</code> parameter is never applied, so it is impossible to change it.  This is fixed with the following patch:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="diff --git a/src/main/java/org/elasticsearch/index/search/MatchQuery.java b/src/main/java/org/elasticsearch/index/search/MatchQuery.java
index b776416..7cc1f4f 100644
--- a/src/main/java/org/elasticsearch/index/search/MatchQuery.java
+++ b/src/main/java/org/elasticsearch/index/search/MatchQuery.java
@@ -303,10 +303,11 @@ public class MatchQuery {
                 if (query instanceof FuzzyQuery) {
                     QueryParsers.setRewriteMethod((FuzzyQuery) query, fuzzyRewriteMethod);
                 }
+                return query;
             }
             int edits = fuzziness.asDistance(term.text());
             FuzzyQuery query = new FuzzyQuery(term, edits, fuzzyPrefixLength, maxExpansions, transpositions);
-            QueryParsers.setRewriteMethod(query, rewriteMethod);
+            QueryParsers.setRewriteMethod((FuzzyQuery) query, fuzzyRewriteMethod);
             return query;
         }
         if (mapper != null) {
@@ -318,4 +319,4 @@ public class MatchQuery {
         return new TermQuery(term);
     }

-}
\ No newline at end of file
+}"><pre class="notranslate"><code class="notranslate">diff --git a/src/main/java/org/elasticsearch/index/search/MatchQuery.java b/src/main/java/org/elasticsearch/index/search/MatchQuery.java
index b776416..7cc1f4f 100644
--- a/src/main/java/org/elasticsearch/index/search/MatchQuery.java
+++ b/src/main/java/org/elasticsearch/index/search/MatchQuery.java
@@ -303,10 +303,11 @@ public class MatchQuery {
                 if (query instanceof FuzzyQuery) {
                     QueryParsers.setRewriteMethod((FuzzyQuery) query, fuzzyRewriteMethod);
                 }
+                return query;
             }
             int edits = fuzziness.asDistance(term.text());
             FuzzyQuery query = new FuzzyQuery(term, edits, fuzzyPrefixLength, maxExpansions, transpositions);
-            QueryParsers.setRewriteMethod(query, rewriteMethod);
+            QueryParsers.setRewriteMethod((FuzzyQuery) query, fuzzyRewriteMethod);
             return query;
         }
         if (mapper != null) {
@@ -318,4 +319,4 @@ public class MatchQuery {
         return new TermQuery(term);
     }

-}
\ No newline at end of file
+}
</code></pre></div>
<h2 dir="auto">Unused <code class="notranslate">rewrite</code> parameter</h2>
<p dir="auto">The <code class="notranslate">match</code> query accepts a <code class="notranslate">rewrite</code> parameter which is never used.</p>
<h2 dir="auto">Bad rewriting of <code class="notranslate">match_phrase_prefix</code></h2>
<p dir="auto">The <code class="notranslate">match_phrase_prefix</code> should (IMO) use a <code class="notranslate">constant_score_auto</code> rewrite on the final term (and this should be settable with <code class="notranslate">rewrite</code>), but this functionality is implemented with the MultiPhraseQuery which doesn't support the rewrite methods.</p>