How to write Multiple fuzziness Query in Elastic

Hello Folks,
i have this text in a Field "word" Like bellow,
"word": """Here is my text , in the future , we will all be able to have a nice life hämaton or whatever subdural or what ever bltng ot to have cronish"""

i want to write a multipli fuzzy or fuzziness Search Query(searching for more than one word) to be able to look for both words "hämaton" and "bltng" in the Field "word".

i tried this like below:

GET my_index/_search
{
  "query": {
    "fuzzy": { "word" : "hämaton" },
    "fuzzy":{"word": "bltng"}
  }
}

**or this**

GET my_index/_search
{
  "query": {
    "match": {
      "word": {
        "query":     "hämaton", "bltng "
        "fuzziness": 2
      }
    }
  }
}

But still missing something to understand, why i can not write "fuzzy" twice in a search query or
how to write it , or how to use fuzziness to look for more than word in a text?

Can anybody please help me to correct my above Query?
thx.

Please format your code, logs or configuration files using </> icon as explained in this guide and not the citation button. It will make your post more readable.

Or use markdown style like:

```
CODE
```

This is the icon to use if you are not using markdown format:

There's a live preview panel for exactly this reasons.

Lots of people read these forums, and many of them will simply skip over a post that is difficult to read, because it's just too large an investment of their time to try and follow a wall of badly formatted text.
If your goal is to get an answer to your questions, it's in your interest to make it as easy to read and understand as possible.
Please update your post.

You can use a bool query with 2 should clauses or 2 must clauses depending if you want to have one of the query that matches or both.

thank you to let me make my Code as simple readable as possible .

like you said , i tried to write the should query like below:

GET my_index/_search
{
  "query": {
    "bool": {
      "should": [
        { "match": { "word":  "hämaton" }},
        { "match": { "word": "bltng"   }}
      ]
    }
  }
}


GET my_index\_search
{
  "query": {
    "bool": {
      "should": [
        {
          "match": {
            "word": "hämaton"
          }
          
        }],
      "should": [
        {
          "match": {
            "word": "bltng"
          }
          
        }]
    }}}


But the Question is , where can i put and use "fuzzy" or "fuzziness" in order to be able to search for those words , when they contain typing error.
using 2 should is not allowed, it shows me error" duplicate key 'should' "
thx.

You can put whatever query inside. Did you try? Note that IIRC the match query supports also the fuzziness parameter.

i tried to write 2 should , it did not accept duplicate key 'should'.
otherwise 'should' is not the same as 'fuzzy' or 'fuzziness'.
In the Example above , i tried to look for words "hämaton" and "bltng" , if they are written wrong in a text something like " hmaton" and "blng" , I still have to be able to search for those "hämaton" and "bltng" using the "fuzzy" or "fuzziness".
Using "should" is not like using "fuzzy".
until now this works , but i want to look for more than one word, what should i add here:

GET my_index/_search
{
 
  "query": {
    "bool": {
      "should": [
        { 
          "fuzzy":{"word":  "hämaton"  }
          
        }
      ]
    }
  }
}

Any Suggestions?
thx.

Something like:

GET my_index/_search
{
  "query": {
    "bool": {
      "should": [
        { 
          "fuzzy":{"word":  "hämaton"  }          
        },  { 
          "fuzzy":{"word":  "bltng"  }          
        }
      ]
    }
  }
}

yes it works, i was all the time missing to put { after the comma .
is it possible to write should twice in one Query ??`below it did not accept the key "should twice.

GET my_index\_search
{
  "query": {
    "bool": {
      "should": [
        {
          "match": {
            "word": "hämaton"
          }
          
        }],
      "should": [
        {
          "match": {
            "word": "bltng"
          }
          
        }]
    }}}

thx.

No but why would you do that instead of what I wrote?

As alternative Option.
if i want to say, it "should match this word "hämaton" AND that word "bltng" .

thx.

Then:

GET my_index/_search
{
  "query": {
    "bool": {
      "must": [
        { 
          "fuzzy":{"word":  "hämaton"  }          
        },  { 
          "fuzzy":{"word":  "bltng"  }          
        }
      ]
    }
  }
}

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