# Elasticsearch fuzziness with multi\_match and bool\_prefix type

**URL:** <https://discuss.elastic.co/t/elasticsearch-fuzziness-with-multi-match-and-bool-prefix-type/290735>\
**Category:** Elasticsearch\
**Created:** [December 2, 2021, 7:35am UTC](https://discuss.elastic.co/t/elasticsearch-fuzziness-with-multi-match-and-bool-prefix-type/290735 "2021-12-02T07:35:39Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![konman1989](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/konman1989/32/96728_2.png) [@konman1989](https://discuss.elastic.co/u/konman1989)\
**Post date:** [December 2, 2021, 7:35am UTC](https://discuss.elastic.co/t/elasticsearch-fuzziness-with-multi-match-and-bool-prefix-type/290735/1 "2021-12-02T07:35:39Z")

</div>

I have a set of search\_as\_you\_type\_fields I need to search against. Here is my mapping

```auto
"mappings" : {
      "properties" : {
        "description" : {
          "type" : "search_as_you_type",
          "doc_values" : false,
          "max_shingle_size" : 3
        },
        "questions" : {
          "properties" : {
            "content" : {
              "type" : "search_as_you_type",
              "doc_values" : false,
              "max_shingle_size" : 3
            },
            "tags" : {
              "type" : "text",
              "fields" : {
                "keyword" : {
                  "type" : "keyword"
                }
              }
            }
          }
        },
      
        "title" : {
          "type" : "search_as_you_type",
          "doc_values" : false,
          "max_shingle_size" : 3
        },
      }
    }

```

I am using a multi\_match query with bool\_prefix type.

```auto
"query": {
    "multi_match": {
      "query": "triangle", 
      "type": "bool_prefix",
       "fields": [
           "title",
           "title._2gram",
           "title._3gram",
           "description",
           "description._2gram",
           "description._3gram",
           "questions.content",
           "questions.content._2gram",
           "questions.content._3gram",
           "questions.tags",
           "questions.tags._2gram",
           "questions.tags._3gram"
       ]
    }
  }

```

So far works fine. Now I want to add a typo tolerance which is fuzziness in ES. However, looks like bool\_prefix has some conflicts working with this. So if I modify my query and add "fuzziness": "AUTO" and make an error in a word "triangle" -\> "triangld", it won't get any results.

However, if I am looking for a phrase "right triangle", I have some different behavior:

1. even if no typos is made, I got more results with just "fuzziness": "AUTO" (1759 vs 1267)
2. if I add a typo to the 2d word "right triangdd", it seems to work, however looks like it now pushes the results containing "right" without "triangle" first ("The Bill of Rights", "Due process and right to privacy" etc.) in front.
3. If I make a typo in the 1st word ("righd triangle") or both ("righd triangdd"), the results seems to be just fine. So this is probably the only correct behavior.

I've seen a couple of articles and even GitHub issues that fuzziness does not work in a proper way with a multi\_match query with bool\_prefix, however I can't find a workaround for this. I've tried changing the query type, but looks like bool\_prefix is the only one that supports search as you type and I need to get search result as a user starts typing something.

Since I make all the requests from ES from our backend What I also can do is manipulate a query string to build different search query types if needed. For example, for 1 word searches use one type for multi use another. But I basically need to maintain current behavior.

I've also tried appending a sign "~" or "~1[2]" to the string which seems to be another way of specifying the fuzziness, but the results are rather unclear and performance (search speed) seems to be worse.

My questions are:

1. How can I achieve fuzziness for 1 word searches? so that query "triangld" returns documents containing "triangle" etc.
2. How can I achieve correct search results when the typo in the 2d (last?) word of the query? Like I mentioned above it works, but see the point 2 above
3. Why just adding a fuzziness (see p. 1) returns more results even if the phrase is correct?
4. Anything I need to change in my analyzers etc.?

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [December 30, 2021, 7:35am UTC](https://discuss.elastic.co/t/elasticsearch-fuzziness-with-multi-match-and-bool-prefix-type/290735/2 "2021-12-30T07:35:57Z")

</div>

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