# Use variable for target value (kv)

**URL:** <https://discuss.elastic.co/t/use-variable-for-target-value-kv/78009>\
**Category:** Logstash\
**Created:** [March 9, 2017, 3:27pm UTC](https://discuss.elastic.co/t/use-variable-for-target-value-kv/78009 "2017-03-09T15:27:41Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![florentmair](https://avatars.discourse-cdn.com/v4/letter/f/8e7dd6/32.png) [@florentmair](https://discuss.elastic.co/u/florentmair)\
**Post date:** [March 9, 2017, 3:27pm UTC](https://discuss.elastic.co/t/use-variable-for-target-value-kv/78009/1 "2017-03-09T15:27:41Z")

</div>

Hi

I want to use a fieldname to setup the "target" field in KV plugin, but it's doesn't work 🙂

```
filter {
if [message] =~ /^NUMBER OF .*:/ {
    grok {
         match => { "message" => "^NUMBER OF %{DATA:fieldinfo} :"}

    }
    mutate {
       gsub => ["fieldinfo", " ", "_"]
    }
       kv {
         field_split => "\n"
         target => "NB_%{fieldinfo}"
         trim => " "
         trimkey => " <>"
       }
} else {
    drop{}
}
}

```

my result :

```
{
               "path" => "/tmp/input",
         "@timestamp" => 2017-03-09T15:15:09.147Z,
    "NB_%{fieldinfo}" => {
        "NamedUsers" => "24488",
            "Groups" => "16781"
    },
           "@version" => "1",
               "host" => "XXXXX",
          "fieldinfo" => "USERS_AND_GROUPS",
            "message" => "NUMBER OF USERS AND GROUPS :\n Named Users = 24488 \n Groups = 16781 \n ",
               "tags" => [
        [0] "multiline"
    ]
}

```

Any idea ?  
Thanks  
Florent

---

<div class="post-metadata">

**Author:** ![magnusbaeck](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/magnusbaeck/32/44943_2.png) [@magnusbaeck](https://discuss.elastic.co/u/magnusbaeck)\
**Post date:** [March 9, 2017, 3:32pm UTC](https://discuss.elastic.co/t/use-variable-for-target-value-kv/78009/2 "2017-03-09T15:32:30Z")

</div>

Known limitation:

> <https://github.com/logstash-plugins/logstash-filter-kv/issues/35>

---

<div class="post-metadata">

**Author:** ![florentmair](https://avatars.discourse-cdn.com/v4/letter/f/8e7dd6/32.png) [@florentmair](https://discuss.elastic.co/u/florentmair)\
**Post date:** [March 9, 2017, 3:51pm UTC](https://discuss.elastic.co/t/use-variable-for-target-value-kv/78009/3 "2017-03-09T15:51:59Z")

</div>

Thank you, i will try the workaround

---

<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:** [April 6, 2017, 3:52pm UTC](https://discuss.elastic.co/t/use-variable-for-target-value-kv/78009/4 "2017-04-06T15:52:13Z")

</div>

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