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

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
          }
     }
}

@elastic

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 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 for your phrase query clause

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

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