Minimum Match in Elasticsearch Query DSL

Terms query in Elasticsearch allows us to search multiple terms in content. If you want to implement restriction whether one term, two terms or all terms should match, then you can use minimum_match in Elasticsearch query . For Example : If we want to search documents which is belongs in “mobile” and “mobile-accessories” category then Elasticsearch query DSL look like below.

Minimum Match in Elasticsearch Query DSL

{
    "query": {
        "terms": {
            "category": [
                "mobile",
                "mobile-accessories"
            ],
            "minimum_match": 1
        }
    }
}

The Above query returns all the document which is belongs to one or both categories. Because we have set the minimum_match to 1 here. If we want the query to match all categories, we set the minimum_match property to 2.

(Visited 155 times, 3 visits today)