10

I'm trying to filter my elasticsearch's result, it must return the results which are 80% compatible with the search text.

When I do this for just one key, the minimum_should_match works perfect:

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

When I search using more than one key, the minimum_should_match doesn't work right, return the results with 70% compatibility:

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

As far as I can think of, I need to set minimum_should_match by key, but I don't know how to do the same. If someone can help me out in doing so, will be great.

Prerna Jain
  • 1,240
  • 2
  • 16
  • 34
Alessandro Gomes
  • 521
  • 1
  • 5
  • 14

1 Answers1

11

I needed to use bool and multi_match, this is 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%"
                     }
                  }
               ]
            }
         }
      }
   }
}
Alessandro Gomes
  • 521
  • 1
  • 5
  • 14
  • 1
    Or have a look at the different [types](http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/query-dsl-multi-match-query.html#multi-match-types) available since 1.1 with the multi_match query. That might help as well. – javanna Mar 28 '14 at 10:20
  • Not what I was looking for, but great to know that I can query like this as well. – shijin Oct 11 '19 at 13:46