How to use minimum_should_match searching for more than one field?

Asked

Viewed 60 times

0

I am trying to filter my Elasticsearch result where the results should be returned where they are 80% compatible with the searched text.

When I use only one column the rule of minimum_should_match works perfectly:

{
   "size":30,
   "from":930,
   "query":{
      "filtered":{
         "query":{
            "query_string":{
               "default_field":"campo1",
               "query":"portugues",                  
               "minimum_should_match":"80%"
            }
         }
      }
   }
}

When I search for more than one field no matter what value I put in minimum_should_match that the same amount of results is always returned:

{
   "size":30,
   "from":123420,
   "query":{
      "filtered":{
         "query":{
            "query_string":{
               "default_operator":"or",
               "query":"portugues",
               "fields":[
                  "campo1",
                  "campo2^5",
                  "campo3"
               ],
               "minimum_should_match":"80%"
            }
         }
      }
   }
}

From what I’m checking I probably have to insert a minimum_should_match for each column or something.

1 answer

1


I had to use the bool and multi_match, this is the right way:

{
   "size":"30",
   "from":0,
   "query":{
      "filtered":{
         "query":{
            "bool":{
               "should":[
                  {
                     "multi_match":{
                        "query":"portugues",
                        "type":"cross_fields",
                        "fields":[
                           "campo1^3",
                           "campo2^5",
                           "campo3^3"
                        ],
                        "minimum_should_match":"80%"
                     }
                  }
               ]
            }
         }
      }
   }
}

Browser other questions tagged

You are not signed in. Login or sign up in order to post.