How to use fuzzy and match phrase?

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 ?

match_phrase doesn't work with fuzziness.
Try with span queries:

{  
   "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
               }
            }
         ]
      }
   }
}
1 Like

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