# Elasticsearch - Avoid Word based and fuzzy based match when Phrase is matched

**URL:** <https://discuss.elastic.co/t/elasticsearch-avoid-word-based-and-fuzzy-based-match-when-phrase-is-matched/161651>\
**Category:** Elasticsearch\
**Created:** [December 20, 2018, 9:46am UTC](https://discuss.elastic.co/t/elasticsearch-avoid-word-based-and-fuzzy-based-match-when-phrase-is-matched/161651 "2018-12-20T09:46:43Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Nikesh](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/nikesh/32/86579_2.png) [@Nikesh](https://discuss.elastic.co/u/Nikesh)\
**Post date:** [December 20, 2018, 9:46am UTC](https://discuss.elastic.co/t/elasticsearch-avoid-word-based-and-fuzzy-based-match-when-phrase-is-matched/161651/1 "2018-12-20T09:46:43Z")

</div>

Hi,

I have a query which searches on phrase, word level and fuzziness of words searched for.  
Is there a method where in I can restrict word and fuzzy matches when exact phrase is matched?  
Query developed is :

```
{
"query" : {
"bool": {
            "should": [
              
              {
                "multi_match": {
                  "query": "this is a test query",
                  "type": "phrase",
                  "boost": "100",
                  "slop": "2",
                  "fields": [
               
                  ]
                }
              },
              {
                "multi_match": {
                  "query": "this is a test query",
                   "analyzer": "whitespace",
                  "fields": [
                   
                  ]
                }
              },
              {
                "multi_match": {
                  "query": "this is a test query",
                  "analyzer": "whitespace",
                    "fuzziness": "AUTO",
                  "fields": [
                  ]
                }
              }
            ],
            "minimum_should_match": 1
          }
     }
}
```

---

<div class="post-metadata">

**Author:** ![Nikesh](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/nikesh/32/86579_2.png) [@Nikesh](https://discuss.elastic.co/u/Nikesh)\
**Post date:** [December 24, 2018, 11:45am UTC](https://discuss.elastic.co/t/elasticsearch-avoid-word-based-and-fuzzy-based-match-when-phrase-is-matched/161651/2 "2018-12-24T11:45:44Z")

</div>

@elastic

---

<div class="post-metadata">

**Author:** ![Mark\_Harwood](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/mark_harwood/32/10538_2.png) [@Mark\_Harwood](https://discuss.elastic.co/u/Mark_Harwood)\
**Post date:** [December 24, 2018, 12:05pm UTC](https://discuss.elastic.co/t/elasticsearch-avoid-word-based-and-fuzzy-based-match-when-phrase-is-matched/161651/3 "2018-12-24T12:05:21Z")

</div>

> [@Nikesh](#):
>
> Is there a method where in I can restrict word and fuzzy matches when exact phrase is matched?

It's designed to be a distributed system - it would be hard to tell one machine to stop any fuzzy-based matching because another machine has uncovered an exact-phrase match.  
If you want to only return exact matches in the case a phrase exists then this would be work your client would need to do. A few ideas come to mind:

1. Your client tries a phrase search first and only tries a fuzzy matching search if there's no results
2. Your client issues an [msearch](https://www.elastic.co/guide/en/elasticsearch/reference/current/search-multi-search.html) request with two queries - one an exact phrase search and one a fuzzy search. To avoid any overlap in results you'd need to add a `must_not` clause to the fuzzy search which would exclude exact phrase matches.
3. As in your current example - you'd need to boost exact phrase matches dramatically and your client could drop any documents below a score threshold that splits exact phrases and other forms of match.
4. Another way of marking queries that matched (other than big-boost scores in #3 ) is to use [named queries](https://www.elastic.co/guide/en/elasticsearch/reference/current/search-request-named-queries-and-filters.html) for your phrase query clause

Bear in mind any aggregations or pagination may be complicated depending on the choices you make.

---

<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:** [January 21, 2019, 12:05pm UTC](https://discuss.elastic.co/t/elasticsearch-avoid-word-based-and-fuzzy-based-match-when-phrase-is-matched/161651/4 "2019-01-21T12:05:26Z")

</div>

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