# How to get all the suggestions in completion query

**URL:** <https://discuss.elastic.co/t/how-to-get-all-the-suggestions-in-completion-query/372882>\
**Category:** Elasticsearch\
**Created:** [January 7, 2025, 7:22am UTC](https://discuss.elastic.co/t/how-to-get-all-the-suggestions-in-completion-query/372882 "2025-01-07T07:22:38Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Capybara07](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/capybara07/32/140518_2.png) [@Capybara07](https://discuss.elastic.co/u/Capybara07)\
**Post date:** [January 7, 2025, 7:22am UTC](https://discuss.elastic.co/t/how-to-get-all-the-suggestions-in-completion-query/372882/1 "2025-01-07T07:22:38Z")

</div>

so here is my mapping

```auto
"skills_completion": {
      "type": "completion",
      "contexts": [
        {
          "name": "api_key",
          "type": "category"
        }
      ]
      },

```

and below are my inserted data in skills\_completion

```auto
{ "input": ["deal", "don", "drag", "resource", "question", "player", "training"], "contexts": { "api_key": "4" } }

{ "input": ["deal", "dog", "group", "resource", "question", "player", "training"], "contexts": { "api_key": "4" } }

```

thing is that when I query it like this

```auto
POST /cvs/_search
{
  "_source": false,
  "suggest": {
    "name-suggest": {
      "prefix": "d", // Change this prefix as needed
      "completion": {
        "field": "skills_completion",
        "skip_duplicates": true,
        "contexts": {
          "api_key": [
            {
              "context": "4"
            }
          ]
        }
      }
    }
  }
}

```

thing is that In response I get only deal and not deal, dog, don, drag  
however when I query with prefix = "do" then I do get dog,don

what is the issue here is it due to an array that I am providing for completion or something else

---

<div class="post-metadata">

**Author:** ![iulia](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/iulia/32/124658_2.png) [@iulia](https://discuss.elastic.co/u/iulia)\
**Post date:** [January 7, 2025, 12:16pm UTC](https://discuss.elastic.co/t/how-to-get-all-the-suggestions-in-completion-query/372882/2 "2025-01-07T12:16:08Z")

</div>

Hi!

I was able to replicate your results and there are a few things to note.  
In the current state you are searching for which documents have a match to your prefix query - and the result is the first match found per document.

Since you have `skip_duplicates` to true in the search with `d` you are getting `deal` back only once (if you turn duplicates to false both documents will be returned due to the deal match).  
In the case of searching for `do` you get back the first result in each document (`dog` and `don`).

This is the expected behavior since your input is formated as two documents and your query is meant to return the document indexes that match the prefix.

If you want to get all possible terms, you can add each term as its own document instead. So for example if I input as:

```auto
PUT test_complete/_doc/2?refresh
{
  "skills_completion" : 
   { "input": ["deal"], "contexts": { "api_key": "4" } }

}

PUT test_complete/_doc/3?refresh
{
  "skills_completion" : 
   { "input": ["dog"], "contexts": { "api_key": "4" } }

}

PUT test_complete/_doc/4?refresh
{
  "skills_completion" : 
   { "input": ["don"], "contexts": { "api_key": "4" } }

}

```

When you query with the `d` prefix you now get all three documents back.

Hope this helps!  
Iulia
