# Minimun\_should\_match does not work at ES 5.\* version

**URL:** <https://discuss.elastic.co/t/minimun-should-match-does-not-work-at-es-5-version/88642>\
**Category:** Elasticsearch\
**Created:** [June 8, 2017, 1:16am UTC](https://discuss.elastic.co/t/minimun-should-match-does-not-work-at-es-5-version/88642 "2017-06-08T01:16:28Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![linda](https://avatars.discourse-cdn.com/v4/letter/l/67e7ee/32.png) [@linda](https://discuss.elastic.co/u/linda)\
**Post date:** [June 8, 2017, 1:16am UTC](https://discuss.elastic.co/t/minimun-should-match-does-not-work-at-es-5-version/88642/1 "2017-06-08T01:16:28Z")

</div>

_I deploy ES 5. version, and use ngram as char split like url [https://www.elastic.co/guide/en/elasticsearch/guide/current/ngrams-compound-words.html](https://www.elastic.co/guide/en/elasticsearch/guide/current/ngrams-compound-words.html),_\*  
**Index settings and mappings as above url like this:**  
PUT /my\_index  
{  
"settings": {  
"analysis": {  
"filter": {  
"trigrams\_filter": {  
"type": "ngram",  
"min\_gram": 3,  
"max\_gram": 3  
}  
},  
"analyzer": {  
"trigrams": {  
"type": "custom",  
"tokenizer": "standard",  
"filter": [  
"lowercase",  
"trigrams\_filter"  
]  
}  
}  
}  
},  
"mappings": {  
"my\_type": {  
"properties": {  
"text": {  
"type": "string",  
"analyzer": "trigrams"  
}  
}  
}  
}  
}  
**Then index data as above url:**  
POST /my\_index/my\_type/\_bulk  
{ "index": { "\_id": 1 }}  
{ "text": "Aussprachewörterbuch" }  
{ "index": { "\_id": 2 }}  
{ "text": "Militärgeschichte" }  
{ "index": { "\_id": 3 }}  
{ "text": "Weißkopfseeadler" }  
{ "index": { "\_id": 4 }}  
{ "text": "Weltgesundheitsorganisation" }  
{ "index": { "\_id": 5 }}  
{ "text": "Rindfleischetikettierungsüberwachungsaufgabenübertragungsgesetz" }

**But minimum\_should\_match does not work when excute phrase as follows:**  
GET /my\_index/my\_type/\_search  
{  
"query": {  
"match": {  
"text": {  
"query": "Gesundheit",  
"minimum\_should\_match": "80%"  
}  
}  
}  
}  
result still matches “Militär-ges-chichte” and “Rindfleischetikettierungsüberwachungsaufgabenübertragungs-ges-etz,” both of which also contain the trigram ges. Any ideas to process this condition? thanks

---

<div class="post-metadata">

**Author:** ![Clinton\_Gormley](https://avatars.discourse-cdn.com/v4/letter/c/50afbb/32.png) [@Clinton\_Gormley](https://discuss.elastic.co/u/Clinton_Gormley)\
**Post date:** [June 8, 2017, 5:03pm UTC](https://discuss.elastic.co/t/minimun-should-match-does-not-work-at-es-5-version/88642/2 "2017-06-08T17:03:54Z")

</div>

You can use the validate-query API to figure out why this happens.

```auto
GET /my_index/_validate/query?explain
{
  "query": {
    "match": {
      "text": {
        "query": "Gesundheit",
        "minimum_should_match": "80%"
      }
    }
  }
}

```

returns:

```auto
"explanation": "Synonym(text:dhe text:eit text:esu text:ges text:hei text:ndh text:sun text:und)"

```

In other words, all the trigrams are considered to be synonyms and, as such, are treated as a single word when using `minimum_must_match`. This is because you've used the ngram token filter, which returns the same term position for all ngrams in a single word.

The internal `Synonym` query is a fairly recent addition which changed the interaction of `minimum_should_match` with tokens in the same position.

If you use the ngrams tokenizer instead, then you will get what you want:

```auto
PUT /my_index
{
  "settings": {
    "analysis": {
      "tokenizer": {
        "trigrams_filter": {
          "type": "ngram",
          "min_gram": 3,
          "max_gram": 3
        }
      },
      "analyzer": {
        "trigrams": {
          "type": "custom",
          "tokenizer": "trigrams_filter",
          "filter": [
            "lowercase"
          ]
        }
      }
    }
  },
  "mappings": {
    "my_type": {
      "properties": {
        "text": {
          "type": "string",
          "analyzer": "trigrams"
        }
      }
    }
  }
}

POST /my_index/my_type/_bulk
{ "index": { "_id": 1 }}
{ "text": "Aussprachewörterbuch" }
{ "index": { "_id": 2 }}
{ "text": "Militärgeschichte" }
{ "index": { "_id": 3 }}
{ "text": "Weißkopfseeadler" }
{ "index": { "_id": 4 }}
{ "text": "Weltgesundheitsorganisation" }
{ "index": { "_id": 5 }}
{ "text": "Rindfleischetikettierungsüberwachungsaufgabenübertragungsgesetz" }

GET /my_index/_validate/query?explain
{
  "query": {
    "match": {
      "text": {
        "query": "Gesundheit",
        "minimum_should_match": "80%"
      }
    }
  }
}

```

returns:

```auto
"explanation": "(text:ges text:esu text:sun text:und text:ndh text:dhe text:hei text:eit)~6"

```

and the query:

```auto
GET /my_index/_search
{
  "query": {
    "match": {
      "text": {
        "query": "Gesundheit",
        "minimum_should_match": "80%"
      }
    }
  }
}

```

returns just:

```auto
    "hits": [
      {
        "_index": "my_index",
        "_type": "my_type",
        "_id": "4",
        "_score": 4.2928576,
        "_source": {
          "text": "Weltgesundheitsorganisation"
        }
      }
    ]

```

---

<div class="post-metadata">

**Author:** ![linda](https://avatars.discourse-cdn.com/v4/letter/l/67e7ee/32.png) [@linda](https://discuss.elastic.co/u/linda)\
**Post date:** [June 9, 2017, 6:00am UTC](https://discuss.elastic.co/t/minimun-should-match-does-not-work-at-es-5-version/88642/3 "2017-06-09T06:00:09Z")

</div>

Thank for your reply.

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [July 7, 2017, 6:00am UTC](https://discuss.elastic.co/t/minimun-should-match-does-not-work-at-es-5-version/88642/4 "2017-07-07T06:00:10Z")

</div>

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.
