Getting this error undefined local variable or method `demo1' for #<Fluent::Plugin::ElasticsearchOutputDynamic:00000000000f00> (NameError)

I have used this configuration:-

<filter test.*>
  @type record_modifier
  remove_keys _dummy1_
    _dummy1_ ${record.has_key?("demo") ? record["demo1"]=record["demo"]["name"]:record["demo1"] = 'UNAVAILABLE'}
    demo1 ${record["demo1"]}

<match test.**>
  @type elasticsearch_dynamic
  host elasticsearch
  port 9200
  time_key_exclude_timestamp true
  logstash_format true
  logstash_prefix ${demo1}

If i pass only ${demo1} in logstash_prefix it gives the below error like this:- logstash_prefix ${demo1}

undefined local variable or method `demo1’ for #Fluent::Plugin::ElasticsearchOutputDynamic:00000000000f00 (NameError)

But if i pass ${record[“demo1”]} it works as expected ex:- logstash_prefix ${record[“demo1”]}

Could someone please explain how to resolve this error?