Home > OS >  Elastic Search minimum_should_match
Elastic Search minimum_should_match

Time:09-20

I am analyzing some Elastic Search queries to understand the API better, and I am confused by these queries

"query": {
        "function_score": {
            "query": {
                "bool": {
                    "must": {
                        "match": {
                            "title_normalized": {
                                "query": "here goes the query",
                                "minimum_should_match": 2
                            }
                        }
                    },
                    "filter": ...
                },
            },
        },
}

how does minimum_should_match make sense in this context ? There is no should clause, but we are inside a match clause.

Similarly, here

"query": {
        "function_score": {
            "query": {
                "bool": {
                    "must": ...
                    "filter": {
                        "bool": {
                            "should": [{
                                "match": {
                                    "title_normalized": {
                                        "query": "here goes",
                                        "minimum_should_match": 2
                                    }
                                }
                            }, {
                                "match": {
                                    "title_normalized": {
                                        "query": "the query",
                                        "minimum_should_match": 2
                                    }
                                }
                            }],
                            "minimum_should_match": 1
                        }
                    }
                },
            },
        },
}

I understand the "minimum_should_match": 1 at the same indentation level as should, but what about the minimum_should_match nested within the match clauses? What do those mean?

CodePudding user response:

the use of "minimum_should_match" in the "match" clause determines the min number of terms to match. Ex: you have the doc "here goes the query" and your query is:

   "match": {
      "title_normalized": {
        "query": "here goes",
        "minimum_should_match": 2
      }
    }

you will retrieve the document as there are two matching terms.

If you change "minimum_should_match" to 3, there will be no results because the minimum of matching terms is 3 and your query has only 2.

  • Related