How to use minimum_should_match searching for more than one field?

0

I'm 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 minimum_should_match rule 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 it does not 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 probably checking I have to insert a minimum_should_match for each column or something.

    
asked by anonymous 27.03.2014 / 18:51

1 answer

1

I had to use 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%"
                     }
                  }
               ]
            }
         }
      }
   }
}
    
28.03.2014 / 01:07