# ElasticSearch autocomplete/suggest by token

**URL:** <https://discuss.elastic.co/t/elasticsearch-autocomplete-suggest-by-token/291854>\
**Category:** Elasticsearch\
**Created:** [December 14, 2021, 6:15pm UTC](https://discuss.elastic.co/t/elasticsearch-autocomplete-suggest-by-token/291854 "2021-12-14T18:15:12Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![abhinav-nath](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/abhinav-nath/32/98935_2.png) [@abhinav-nath](https://discuss.elastic.co/u/abhinav-nath)\
**Post date:** [December 14, 2021, 6:15pm UTC](https://discuss.elastic.co/t/elasticsearch-autocomplete-suggest-by-token/291854/1 "2021-12-14T18:15:12Z")

</div>

I want to create search suggestions based on the **tokens** (and not full documents) that are present in my index.

For example:  
I have a simple index for **movies** in which I have these two documents:

1. `{"name":"Captain America"}`
2. `{"name":"American Made"}`

If I type **"ame"** then I should get two suggestions (as tokens)

1. `america`
2. `american`

Similarly if I type **"cap**" then I should get **"captain"** and not **"Captain America"**

> I am having exact same problem as this post:  
> [Elasticsearch autocomplete- / suggest by token](https://discuss.elastic.co/t/elasticsearch-autocomplete-suggest-by-token/18392)

I have gone through all types of suggesters and seems like they are focused on returning the whole documents rather than the tokens.

Apache Solr serves this requirement through its autosuggest functionality:

For example, if I type `kni` then Solr would return `knives`, `knife` and `knit` as suggestions (based on the tokens coming from the indexed documents)

```auto
{
  "responseHeader":{
    "status":0,
    "QTime":19},
  "spellcheck":{
    "suggestions":[
      "kni",{
        "numFound":3,
        "startOffset":0,
        "endOffset":3,
        "suggestion":["knives",
          "knife",
          "knit"]}],
    "collations":[
      "collation","knives"]}}

```

> One of the probable solution is mentioned in this StackOverflow thread:  
> [Elasticsearch autocomplete or autosuggest by token - Stack Overflow](https://stackoverflow.com/questions/24391598/elasticsearch-autocomplete-or-autosuggest-by-token)
> 
> But it relies on explicitly adding all the suggestions in every document. This seems to be a tedious approach.

Please let me know if this can be achieved somehow in a better way.

Thanks in advance.

---

<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:** [January 11, 2022, 6:15pm UTC](https://discuss.elastic.co/t/elasticsearch-autocomplete-suggest-by-token/291854/2 "2022-01-11T18:15:59Z")

</div>

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