# Grok - how to add field with values from existing fields?

**URL:** https://discuss.elastic.co/t/grok-how-to-add-field-with-values-from-existing-fields/114277
**Category:** Logstash
**Created:** [January 5, 2018, 11:31am UTC](https://discuss.elastic.co/t/grok-how-to-add-field-with-values-from-existing-fields/114277 "2018-01-05T11:31:26Z")
**Posts on this page:** 7
**Page:** 1

<div class="post-metadata">

### Author: ![qubusp](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/qubusp/32/26282_2.png) [@qubusp](https://discuss.elastic.co/u/qubusp)
#### Post date: [January 5, 2018, 11:31am UTC](https://discuss.elastic.co/t/grok-how-to-add-field-with-values-from-existing-fields/114277/1 "2018-01-05T11:31:26Z")

</div>

The following is a pull of metrics from a jmx application.  
The question is how to build a grok pattern, which will use the metric\_path: as field name(it's changing constantly) and use metric\_value\_number as the numeric value?

Thank you in advance.

````auto
metric_value_number:1 
path:/opt/jmxd/ 
@timestamp:January 5th 2018, 12:16:16.652 
@version:1 
host:server1 
metric_path:dumper.PlugableGroupConsumer-0.running_bool 
type:jmx 
_id:NLEJxmABgpl3QdqYJlaX 
_type:jmx 
_index:jmx-2018.01.05 
_score: -```
````

---

<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: [January 5, 2018, 12:06pm UTC](https://discuss.elastic.co/t/grok-how-to-add-field-with-values-from-existing-fields/114277/2 "2018-01-05T12:06:22Z")

</div>

```nohighlight
mutate {
  add_field => {
    "%{metric_path}" => "%{metric_value_number}"
  }
}

```

---

<div class="post-metadata">

### Author: ![qubusp](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/qubusp/32/26282_2.png) [@qubusp](https://discuss.elastic.co/u/qubusp)
#### Post date: [January 5, 2018, 12:55pm UTC](https://discuss.elastic.co/t/grok-how-to-add-field-with-values-from-existing-fields/114277/3 "2018-01-05T12:55:27Z")

</div>

Hey, thanks a lot, that worked, but the value comes out as a string. Is there a way to make it numeric?

maybe:

```auto

filter {
mutate {
 add_field => {
   "%{metric_path}" => "%{metric_value_number}"
 }}
filter{
mutate{
convert => {
"dumper.BufferPool.direct.Count" => "integer",
"dumper.BufferPool.direct.Name" => "integer",
"dumper.BufferPool.direct.ObjectName" => "integer",
"dumper.BufferPool.direct.MemoryUsed" => "integer",
"dumper.BufferPool.direct.TotalCapacity" => "integer",
"dumper.BufferPool.mapped.Count" => "integer",
"dumper.BufferPool.mapped.MemoryUsed" => "integer",
"dumper.BufferPool.mapped.Name" => "integer",
"dumper.BufferPool.mapped.ObjectName" => "integer",
"dumper.BufferPool.mapped.TotalCapacity" => "integer",
"dumper.GarbageCollector.ConcurrentMarkSweep.CollectionCount" => "integer",
"dumper.GarbageCollector.ConcurrentMarkSweep.CollectionTime" => "integer",
"dumper.GarbageCollector.ParNew.CollectionCount" => "integer",
"dumper.GarbageCollector.ParNew.CollectionTime" => "integer",
"dumper.HdfsDumper-default-urlinfo-click-stream-1_0.errorCounter" => "integer",
"dumper.HdfsDumper-default-urlinfo-click-stream-1_0.filesCounter" => "integer",
"dumper.HdfsDumper-default-urlinfo-click-stream-1_0.messageCounter" => "integer",
"dumper.HdfsDumper-default-urlinfo-click-stream-1_0.writerMessageCounter" => "integer",
"dumper.KafkaGroupMonitor.lastRefresh" => "integer",
"dumper.KafkaGroupMonitor.listOfmyPartitions" => "integer",
"dumper.KafkaGroupMonitor.maxLag" => "integer",
"dumper.KafkaGroupMonitor.myClientsStr" => "integer",
"dumper.KafkaGroupMonitor.myMaxLag" => "integer",
"dumper.KafkaGroupMonitor.myPartitions" => "integer",
"dumper.KafkaGroupMonitor.orphanPartitions" => "integer",
"dumper.Memory.HeapMemoryUsage.committed" => "integer",
"dumper.Memory.HeapMemoryUsage.init" => "integer",
"dumper.Memory.HeapMemoryUsage.max" => "integer",
"dumper.Memory.HeapMemoryUsage.used" => "integer",
"dumper.Memory.NonHeapMemoryUsage.committed" => "integer",
"dumper.Memory.NonHeapMemoryUsage.init" => "integer",
"dumper.Memory.NonHeapMemoryUsage.max" => "integer",
"dumper.Memory.NonHeapMemoryUsage.used" => "integer",
"dumper.Memory.ObjectName" => "integer",
"dumper.Memory.ObjectPendingFinalizationCount" => "integer",
"dumper.Memory.Verbose_bool" => "integer",
"dumper.PlugableGroupConsumer-0.errorCounter" => "integer",
"dumper.PlugableGroupConsumer-0.messageCounter" => "integer",
"dumper.PlugableGroupConsumer-0.running_bool" => "integer",
"dumper.Runtime.StartTime" => "integer",
"dumper.Runtime.Uptime" => "integer",
"dumper.UrlInfoDumperApp.messageCounter.messageCounter" => "integer",
"dumper.maxFetcherLag.Value" => "integer"
 }}
}
}

```

---

<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: [January 5, 2018, 9:14pm UTC](https://discuss.elastic.co/t/grok-how-to-add-field-with-values-from-existing-fields/114277/4 "2018-01-05T21:14:57Z")

</div>

Yes, or if you don't want to enumerate all fields you could write a snippet of Ruby in a ruby filter to e.g. convert any field with a dot in the name.

---

<div class="post-metadata">

### Author: ![qubusp](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/qubusp/32/26282_2.png) [@qubusp](https://discuss.elastic.co/u/qubusp)
#### Post date: [January 6, 2018, 6:45am UTC](https://discuss.elastic.co/t/grok-how-to-add-field-with-values-from-existing-fields/114277/5 "2018-01-06T06:45:57Z")

</div>

should i use just convert or is there something better for that . for the sake of testing i tried this on a completely new index and it keeps pulling the numbers as strings.

---

<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: [January 6, 2018, 9:58am UTC](https://discuss.elastic.co/t/grok-how-to-add-field-with-values-from-existing-fields/114277/6 "2018-01-06T09:58:20Z")

</div>

> should i use just convert or is there something better for that .

You're using the right tool.

> for the sake of testing i tried this on a completely new index and it keeps pulling the numbers as strings.

Please show an example document, e.g. by copy/pasting from Kibana's JSON tab.

---

<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: [February 3, 2018, 9:58am UTC](https://discuss.elastic.co/t/grok-how-to-add-field-with-values-from-existing-fields/114277/7 "2018-02-03T09:58:29Z")

</div>

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