# Ngrams for compound words in ES 2.\*

**URL:** <https://discuss.elastic.co/t/ngrams-for-compound-words-in-es-2/46157>\
**Category:** Elasticsearch\
**Created:** [April 3, 2016, 11:16am UTC](https://discuss.elastic.co/t/ngrams-for-compound-words-in-es-2/46157 "2016-04-03T11:16:10Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![tallakh](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/tallakh/32/8860_2.png) [@tallakh](https://discuss.elastic.co/u/tallakh)\
**Post date:** [April 3, 2016, 11:16am UTC](https://discuss.elastic.co/t/ngrams-for-compound-words-in-es-2/46157/1 "2016-04-03T11:16:10Z")

</div>

I've been looking into using ngrams to solve searching using wrong spelling and handling complex compound words both in the index and query string.

I came across [ngrams-compound-words](https://www.elastic.co/guide/en/elasticsearch/guide/current/ngrams-compound-words.html) which really fits my needs, but the example query does not work in ES 2.\*. The "minimum\_should\_match" does not seem to work as in the example any more.

Is it possible to achieve the same functionality in ES 2.\*?

The example query looks like this:

```javascript
GET /my_index/my_type/_search
{
    "query": {
        "match": {
            "text": {
                "query": "Gesundheit",
                "minimum_should_match": "80%" //this does not work in ES 2.*
            }
        }
    }
}

```

---

<div class="post-metadata">

**Author:** ![warkolm](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/warkolm/32/39224_2.png) [@warkolm](https://discuss.elastic.co/u/warkolm)\
**Post date:** [April 3, 2016, 11:31pm UTC](https://discuss.elastic.co/t/ngrams-for-compound-words-in-es-2/46157/2 "2016-04-03T23:31:26Z")

</div>

Can you elaborate more on the "doesn't work" part, what are you seeing?

---

<div class="post-metadata">

**Author:** ![tallakh](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/tallakh/32/8860_2.png) [@tallakh](https://discuss.elastic.co/u/tallakh)\
**Post date:** [April 4, 2016, 8:21am UTC](https://discuss.elastic.co/t/ngrams-for-compound-words-in-es-2/46157/3 "2016-04-04T08:21:09Z")

</div>

Changing the "minimum\_should\_match" has no effect on the search result in 2.\*. In my understanding, a higher percentage would only return hits where more of the ngrams from the query matches a ngram in the document. The result should be a higher precision.

So far I've been able to replicate the functionality by splitting the query into ngram and constructing a boolean query, but that complicates this feature a lot.

```javascript
GET /my_index/my_type/_search
{
  "query": {
    "bool": {
      "minimum_should_match": "80%",
      "should": [
        {
          "term": {
            "text": "ges"
          }
        },
        {
          "term": {
            "text": "esu"
          }
        },
        {
          "term": {
            "text": "sun"
          }
        },
        {
          "term": {
            "text": "und"
          }
        },
        {
          "term": {
            "text": "ndh"
          }
        },
        {
          "term": {
            "text": "dhe"
          }
        },
        {
          "term": {
            "text": "hei"
          }
        },
        {
          "term": {
            "text": "eit"
          }
        }
      ]
    }
  }
}

```

---

<div class="post-metadata">

**Author:** ![tallakh](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/tallakh/32/8860_2.png) [@tallakh](https://discuss.elastic.co/u/tallakh)\
**Post date:** [April 6, 2016, 6:52am UTC](https://discuss.elastic.co/t/ngrams-for-compound-words-in-es-2/46157/4 "2016-04-06T06:52:20Z")

</div>

Can anyone confirm that this is the only (or best) way to achieve this functionality in ES 2.\*?

---

<div class="post-metadata">

**Author:** ![mikemccand](https://avatars.discourse-cdn.com/v4/letter/m/f04885/32.png) [@mikemccand](https://discuss.elastic.co/u/mikemccand)\
**Post date:** [April 6, 2016, 10:23am UTC](https://discuss.elastic.co/t/ngrams-for-compound-words-in-es-2/46157/5 "2016-04-06T10:23:01Z")

</div>

Hmm the `minimum_should_match` set on the query string only applies if the query parsed to a boolean query, and coord was disabled. Here's the comment on top of this logic, in ES master `QueryStringBuilder.java`:

```auto
        // If the coordination factor is disabled on a boolean query we don't apply the minimum should match.
        // This is done to make sure that the minimum_should_match doesn't get applied when there is only one word
        // and multiple variations of the same word in the query (synonyms for instance).
        if (query instanceof BooleanQuery && !((BooleanQuery) query).isCoordDisabled()) {
            query = Queries.applyMinimumShouldMatch((BooleanQuery) query, this.minimumShouldMatch());
        }

```

We need to see exactly what query class ES created on parsing your query string with your ngram tokenizer...

---

<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 5, 2017, 11:01pm UTC](https://discuss.elastic.co/t/ngrams-for-compound-words-in-es-2/46157/6 "2017-07-05T23:01:55Z")

</div>


