# Assign completion suggest weight with field value in logstash

**URL:** <https://discuss.elastic.co/t/assign-completion-suggest-weight-with-field-value-in-logstash/293155>\
**Category:** Logstash\
**Created:** [December 29, 2021, 8:30pm UTC](https://discuss.elastic.co/t/assign-completion-suggest-weight-with-field-value-in-logstash/293155 "2021-12-29T20:30:02Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![caseydm](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/caseydm/32/26771_2.png) [@caseydm](https://discuss.elastic.co/u/caseydm)\
**Post date:** [December 29, 2021, 8:30pm UTC](https://discuss.elastic.co/t/assign-completion-suggest-weight-with-field-value-in-logstash/293155/1 "2021-12-29T20:30:03Z")

</div>

I am trying to add a [weight](https://www.elastic.co/guide/en/elasticsearch/reference/current/search-suggesters.html#indexing) to a completion suggest field using logstash, but I'm getting errors. Has anybody done this?

The completion suggester field is set up as follows:

```auto
display_name": {
    "type": "text",
    "fields": {
      "complete": {
        "type": "completion",
        "analyzer": "simple",
        "preserve_separators": true,
        "preserve_position_increments": true,
        "max_input_length": 50
      },
      "keyword": {
        "type": "keyword"
      }
    }
  },

```

What I want to do is add a weight to this field when I add records via logstash. The value for weight is in another field called cited\_by\_count. I tried it in logstash like this:

```
  mutate {
    add_field => { "[display_name][weight]" => "%{cited_by_count}"}
    remove_field => ["json_save", "version"]
  }

```

But when I tried to run it I got multiple errors, saying:

[main] Exception caught while applying mutate filter {:exception=\>"Could not set field 'weight' on object 'Zenun Kast' to value '331'.This is probably due to trying to set a field like [foo][bar] = someValuewhen [foo] is not either a map or a string"}

---

<div class="post-metadata">

**Author:** ![Badger](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/badger/32/25190_2.png) [@Badger](https://discuss.elastic.co/u/Badger)\
**Post date:** [December 29, 2021, 9:44pm UTC](https://discuss.elastic.co/t/assign-completion-suggest-weight-with-field-value-in-logstash/293155/2 "2021-12-29T21:44:09Z")

</div>

> [@caseydm](#):
>
> `add_field => { "[display_name][weight]" =>` ...

The pre-existing field [display\_name] is a string (with the value "Zenun Kast"), not an object, so you cannot create another field inside it.

---

<div class="post-metadata">

**Author:** ![caseydm](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/caseydm/32/26771_2.png) [@caseydm](https://discuss.elastic.co/u/caseydm)\
**Post date:** [December 29, 2021, 10:38pm UTC](https://discuss.elastic.co/t/assign-completion-suggest-weight-with-field-value-in-logstash/293155/3 "2021-12-29T22:38:08Z")

</div>

Any recommendations on how to handle this?

---

<div class="post-metadata">

**Author:** ![Badger](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/badger/32/25190_2.png) [@Badger](https://discuss.elastic.co/u/Badger)\
**Post date:** [December 29, 2021, 11:19pm UTC](https://discuss.elastic.co/t/assign-completion-suggest-weight-with-field-value-in-logstash/293155/4 "2021-12-29T23:19:09Z")

</div>

You need to decide what to do with the existing [display\_name] field. Perhaps rename it with another mutate filter. If you do not want to rename it then use a different name in your add\_field.

---

<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 26, 2022, 11:19pm UTC](https://discuss.elastic.co/t/assign-completion-suggest-weight-with-field-value-in-logstash/293155/5 "2022-01-26T23:19:52Z")

</div>

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