# Is it possible to get (meaningful) term suggestions from an ngram analyzed field?

**URL:** <https://discuss.elastic.co/t/is-it-possible-to-get-meaningful-term-suggestions-from-an-ngram-analyzed-field/183918>\
**Category:** Elasticsearch\
**Created:** [June 3, 2019, 9:08am UTC](https://discuss.elastic.co/t/is-it-possible-to-get-meaningful-term-suggestions-from-an-ngram-analyzed-field/183918 "2019-06-03T09:08:39Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![joargp](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/joargp/32/47315_2.png) [@joargp](https://discuss.elastic.co/u/joargp)\
**Post date:** [June 3, 2019, 9:08am UTC](https://discuss.elastic.co/t/is-it-possible-to-get-meaningful-term-suggestions-from-an-ngram-analyzed-field/183918/1 "2019-06-03T09:08:40Z")

</div>

# Goal

Enable spelling corrections for tokenized fields

## Settings:

```
 {
  "analyzer": {
    "analyzer_search": {
      "filter": ["standard", "lowercase"],
      "char_filter": ["html_strip"],
      "type": "custom",
      "tokenizer": "standard"
    },
    "analyzer": {
      "filter": ["standard", "lowercase"],
      "char_filter": ["html_strip"],
      "type": "custom",
      "tokenizer": "ngram_tokenizer"
    }
 },
 "tokenizer": {
   "ngram_tokenizer": {
    "token_chars": ["letter", "digit"],
     "min_gram": "3",
     "type": "nGram",
     "max_gram": "20"
   }
 }
}

```

## Original mapping

```
{
  "mappings": {
    "searchitemdocument": {
      "properties": {
        "title": {
          "search_analyzer": "analyzer_search",
          "search_quote_analyzer": "analyzer",
          "analyzer": "analyzer",
          "type": "text"
        },
      }
    }
  }
}

```

### Result

This gives suggestions from the ngrams, ie. suggesting `service` -\> `servic`, which is not a word.  
I have solved this by creating an additional field with a different analyzer, like this:

## New mapping for suggestions

```
{
  "mappings": {
    "searchitemdocument": {
      "properties": {
        "title": {
          "search_analyzer": "analyzer_search",
          "search_quote_analyzer": "analyzer",
          "analyzer": "analyzer",
          "type": "text"
        },
        "title_suggest": {
          "analyzer": "no_suggest_analyzer",
          "type": "text"
        }
      }
    }
  }
}

```

I can now use the new field for term suggestion search.  
This works, but I now insert all data twice.

Is there a better way?

---

<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 1, 2019, 9:08am UTC](https://discuss.elastic.co/t/is-it-possible-to-get-meaningful-term-suggestions-from-an-ngram-analyzed-field/183918/2 "2019-07-01T09:08:42Z")

</div>

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