# How to write Multiple fuzziness Query in Elastic

**URL:** <https://discuss.elastic.co/t/how-to-write-multiple-fuzziness-query-in-elastic/176562>\
**Category:** Elasticsearch\
**Created:** [April 12, 2019, 7:43am UTC](https://discuss.elastic.co/t/how-to-write-multiple-fuzziness-query-in-elastic/176562 "2019-04-12T07:43:59Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![samyo](https://avatars.discourse-cdn.com/v4/letter/s/e9c0ed/32.png) [@samyo](https://discuss.elastic.co/u/samyo)\
**Post date:** [April 12, 2019, 7:44am UTC](https://discuss.elastic.co/t/how-to-write-multiple-fuzziness-query-in-elastic/176562/1 "2019-04-12T07:44:00Z")

</div>

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:

```auto
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.

---

<div class="post-metadata">

**Author:** ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)\
**Post date:** [April 12, 2019, 7:56am UTC](https://discuss.elastic.co/t/how-to-write-multiple-fuzziness-query-in-elastic/176562/2 "2019-04-12T07:56:41Z")

</div>

Please format your code, logs or configuration files using `</>` icon as explained in [this guide](https://discuss.elastic.co/t/about-the-elasticsearch-category/21) 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:

 ![image](https://us1.discourse-cdn.com/elastic/original/3X/7/e/7e6e239431ec2d71cbf1beef741f2e93e7cc762c.jpg)

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.

---

<div class="post-metadata">

**Author:** ![samyo](https://avatars.discourse-cdn.com/v4/letter/s/e9c0ed/32.png) [@samyo](https://discuss.elastic.co/u/samyo)\
**Post date:** [April 12, 2019, 8:06am UTC](https://discuss.elastic.co/t/how-to-write-multiple-fuzziness-query-in-elastic/176562/3 "2019-04-12T08:06:41Z")

</div>

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:

```auto
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.

---

<div class="post-metadata">

**Author:** ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)\
**Post date:** [April 12, 2019, 8:23am UTC](https://discuss.elastic.co/t/how-to-write-multiple-fuzziness-query-in-elastic/176562/4 "2019-04-12T08:23:40Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![samyo](https://avatars.discourse-cdn.com/v4/letter/s/e9c0ed/32.png) [@samyo](https://discuss.elastic.co/u/samyo)\
**Post date:** [April 12, 2019, 8:35am UTC](https://discuss.elastic.co/t/how-to-write-multiple-fuzziness-query-in-elastic/176562/5 "2019-04-12T08:35:35Z")

</div>

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:

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

```

Any Suggestions?  
thx.

---

<div class="post-metadata">

**Author:** ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)\
**Post date:** [April 12, 2019, 9:24am UTC](https://discuss.elastic.co/t/how-to-write-multiple-fuzziness-query-in-elastic/176562/6 "2019-04-12T09:24:44Z")

</div>

Something like:

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

```

---

<div class="post-metadata">

**Author:** ![samyo](https://avatars.discourse-cdn.com/v4/letter/s/e9c0ed/32.png) [@samyo](https://discuss.elastic.co/u/samyo)\
**Post date:** [April 12, 2019, 9:29am UTC](https://discuss.elastic.co/t/how-to-write-multiple-fuzziness-query-in-elastic/176562/7 "2019-04-12T09:29:30Z")

</div>

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.

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

```

thx.

---

<div class="post-metadata">

**Author:** ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)\
**Post date:** [April 12, 2019, 9:31am UTC](https://discuss.elastic.co/t/how-to-write-multiple-fuzziness-query-in-elastic/176562/8 "2019-04-12T09:31:00Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![samyo](https://avatars.discourse-cdn.com/v4/letter/s/e9c0ed/32.png) [@samyo](https://discuss.elastic.co/u/samyo)\
**Post date:** [April 12, 2019, 9:34am UTC](https://discuss.elastic.co/t/how-to-write-multiple-fuzziness-query-in-elastic/176562/9 "2019-04-12T09:34:35Z")

</div>

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

thx.

---

<div class="post-metadata">

**Author:** ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)\
**Post date:** [April 12, 2019, 9:47am UTC](https://discuss.elastic.co/t/how-to-write-multiple-fuzziness-query-in-elastic/176562/10 "2019-04-12T09:47:52Z")

</div>

Then:

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

```

---

<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 10, 2019, 9:47am UTC](https://discuss.elastic.co/t/how-to-write-multiple-fuzziness-query-in-elastic/176562/11 "2019-05-10T09:47:55Z")

</div>

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