# How to use fuzzy and match phrase?

**URL:** <https://discuss.elastic.co/t/how-to-use-fuzzy-and-match-phrase/301386>\
**Category:** Elasticsearch\
**Created:** [April 2, 2022, 10:01am UTC](https://discuss.elastic.co/t/how-to-use-fuzzy-and-match-phrase/301386 "2022-04-02T10:01:22Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![asil](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/asil/32/97607_2.png) [@asil](https://discuss.elastic.co/u/asil)\
**Post date:** [April 2, 2022, 10:01am UTC](https://discuss.elastic.co/t/how-to-use-fuzzy-and-match-phrase/301386/1 "2022-04-02T10:01:22Z")

</div>

I'm using `elasticsearch` version 7.6.2

I want to search for a sentence and get results of the same words order (like `match_phrase`) with **sentence** `fuzziness`

for example:

suppose for simplicity i have 1 document in the index:

```
PUT demo_idx/_doc/1
{
  "content": "michael jordan and scottie pippen"
}

```

I want to search the following sentences (with `fuzziness` equals 2):

- "michael jordan and scottie pippen" -\> get 1 result (reason: same sentence)
- "scottie pippen and michael jordan" -\> 0 results (reason: words not in the correct order)
- "ichael jordan and scottie pippen" -\> get 1 result (reason: 'm' of michael is missing, 1 fuzziness)
- "ichae jordan and scottie pippen" -\> get 1 result (reason: 'm' + 'l' of michael are missing, 2 fuzziness)
- "ichael jordan and cottie pippen" -\> get 1 results (reason: 'm' of michael and 's' of scottie are missing, 2 fuzziness)
- "ichael jordan and cottie pippe" -\> 0 results (reason: 'm' of michael and 's' of scottie and 'n' of pippen are missing, 3 fuzziness)
- "ichael jordan and ottie pippen" -\> 0 results (reason: 'm' of michael and 's' + 'c' of scottie are missing, 3 fuzziness)

How can I right the search query in order to get the results I want ?

---

<div class="post-metadata">

**Author:** ![RabBit\_BR](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/rabbit_br/32/82261_2.png) [@RabBit\_BR](https://discuss.elastic.co/u/RabBit_BR)\
**Post date:** [April 6, 2022, 2:56pm UTC](https://discuss.elastic.co/t/how-to-use-fuzzy-and-match-phrase/301386/2 "2022-04-06T14:56:59Z")

</div>

match\_phrase doesn't work with fuzziness.  
Try with [span queries](https://www.elastic.co/guide/en/elasticsearch/reference/current/span-queries.html):

```auto
{  
   "query":{  
      "bool":{  
         "must":[  
            {  
               "span_near":{  
                  "clauses":[  
                     {  
                        "span_multi":{  
                           "match":{  
                              "fuzzy":{  
                                 "content":{  
                                    "value":"ichae",
                                    "fuzziness":2
                                 }
                              }
                           }
                        }
                     },
                     {  
                        "span_multi":{  
                           "match":{  
                              "fuzzy":{  
                                 "content":{  
                                    "value":"jordan",
                                    "fuzziness":2
                                 }
                              }
                           }
                        }
                     },
                     {  
                        "span_multi":{  
                           "match":{  
                              "fuzzy":{  
                                 "content":{  
                                    "value":"and",
                                    "fuzziness":2
                                 }
                              }
                           }
                        }
                     },
                     {  
                        "span_multi":{  
                           "match":{  
                              "fuzzy":{  
                                 "content":{  
                                    "value":"cottie",
                                    "fuzziness":2
                                 }
                              }
                           }
                        }
                     },
                     {  
                        "span_multi":{  
                           "match":{  
                              "fuzzy":{  
                                 "content":{  
                                    "value":"pippe",
                                    "fuzziness":2
                                 }
                              }
                           }
                        }
                     }
                  ],
                  "slop":0,
                  "in_order":true
               }
            }
         ]
      }
   }
}

```

---

<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:** [May 8, 2022, 4:15am UTC](https://discuss.elastic.co/t/how-to-use-fuzzy-and-match-phrase/301386/4 "2022-05-08T04:15:28Z")

</div>

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