Assign completion suggest weight with field value in logstash

I am trying to add a weight 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:

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"}

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.

Any recommendations on how to handle this?

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.

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