# Add weight to chosen completion suggestion

**URL:** <https://discuss.elastic.co/t/add-weight-to-chosen-completion-suggestion/187277>\
**Category:** Elasticsearch\
**Created:** [June 25, 2019, 9:08am UTC](https://discuss.elastic.co/t/add-weight-to-chosen-completion-suggestion/187277 "2019-06-25T09:08:41Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Niels\_van\_Rijn](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/niels_van_rijn/32/45639_2.png) [@Niels\_van\_Rijn](https://discuss.elastic.co/u/Niels_van_Rijn)\
**Post date:** [June 25, 2019, 9:08am UTC](https://discuss.elastic.co/t/add-weight-to-chosen-completion-suggestion/187277/1 "2019-06-25T09:08:42Z")

</div>

Hi!

On a lot of websites with completion suggesters the most popular suggestions are at the top. To my understanding this is why if you type 'iPhone' on a webshop the latest iPhone model will show up at the top, and not the one from 5 years ago.

Now I know one can add a higher `weight` property to a suggestion when you are PUTing a document, but I know beforehand what is going to be popular so I want to append to the `weight` property when a user chooses a suggestion to complete.

I know you can update the weight for a specific option by using scripts (from a very old stackoverflow post, don't know if it works)

```auto
POST /products/iphone/1
{
    "script" : {
        "inline": "ctx._source.suggest.weight += 1"
    }
}

```

But my `suggest` field is populated by a `copy_to` dynamic mapping as shown below.  
Is there any way to create some sort of positive feedback loop for the completed suggestions

```auto
PUT test
{
  "mappings": {
    "properties" : {
      "full_text": {
        "type": "text",
        "store": true
      },
      "suggest" : {
        "type" : "completion"
      }
    },
    "dynamic_templates": [
      {
        "strings": {
          "match_mapping_type": "string",
          "mapping": {
            "type": "keyword",
            "copy_to": ["full_text", "suggest"]
          }
        }
      }
    ]
  }
}

```

P.S. The idea is explained [here](https://discuss.elastic.co/t/help-needed-with-completion-suggestor/109841/3) too in the 3rd point, but there is no concrete answer

---

<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 23, 2019, 9:12am UTC](https://discuss.elastic.co/t/add-weight-to-chosen-completion-suggestion/187277/2 "2019-07-23T09:12:21Z")

</div>

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