# Get value from message and put it into new field

**URL:** <https://discuss.elastic.co/t/get-value-from-message-and-put-it-into-new-field/205045>\
**Category:** Logstash\
**Created:** [October 24, 2019, 11:12am UTC](https://discuss.elastic.co/t/get-value-from-message-and-put-it-into-new-field/205045 "2019-10-24T11:12:55Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![AstroSlazak](https://avatars.discourse-cdn.com/v4/letter/a/bbce88/32.png) [@AstroSlazak](https://discuss.elastic.co/u/AstroSlazak)\
**Post date:** [October 24, 2019, 11:12am UTC](https://discuss.elastic.co/t/get-value-from-message-and-put-it-into-new-field/205045/1 "2019-10-24T11:12:55Z")

</div>

Hi,

I have a problem i want to get Longitude and Latitude from log:  
"2019-10-24 12:01:06,110 [33] INFO XUDP\_Endpoint.UdpEnpoint [(null)] - Data received: AS:17907,NW:77,RD:3003,DT24.10.2019 10.01.05, Longitude:10,457207 ,Latitude:63,4354383 ,Bearing:0,Accuracy:0,Lastr: 0,Distance:-1,GPS: 0,Distance: 0 "

right now i get message:  
"Data received: AS:17907,NW:77,RD:3003,DT24.10.2019 10.01.05,Longitude:10,457207,Latitude:63,4354383,Bearing:0,Accuracy:0,Lastr: 0,Distance:-1,GPS: 0,Distance: 0"

and i want keep it and create two fields: "Longitude and Latitude" which then i want map to geo\_point and display on map. How i suppose to do it ?  
I Create this but it seems doesn't work, it even do not create a new field.

```
filter {
if "log4net.core" in [tags] {
 grok {
  match => { "message" => "(?m)^%{TIMESTAMP_ISO8601:timestamp} \[%{DATA:thread}\] % {DATA:level} %{DATA:logger} - %{GREEDYDATA:message}" }
  overwrite => ["message"]
}
date {
  match => ["timestamp", "yyyy-MM-dd HH:mm:ss,SSS", "yyyy-MM-dd HH:mm:ss.SSSS"]
  timezone => "Europe/Warsaw"
}

if [service.name] == "XXX" {
mutate{
add_field => { "XXXLon" => "%{message}(?<=Longitude:)[0-9]+(,[0-9]+)*" }
		}
mutate{
gsub => ["XXXLon", ",", "."]
}
}
```

---

<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:** [October 24, 2019, 3:23pm UTC](https://discuss.elastic.co/t/get-value-from-message-and-put-it-into-new-field/205045/2 "2019-10-24T15:23:58Z")

</div>

add\_field does not interpret regular expressions. Try

```
    grok { match => { "message" => ["Longitude:(?<Longitude>[0-9]+,[0-9]+)*", "Latitude:(?<Latitude>[0-9]+,[0-9]+)*" ] } break_on_match => false }
    mutate{ gsub => ["Latitude", ",", ".", "Longitude", ",", "."] }
```

---

<div class="post-metadata">

**Author:** ![AstroSlazak](https://avatars.discourse-cdn.com/v4/letter/a/bbce88/32.png) [@AstroSlazak](https://discuss.elastic.co/u/AstroSlazak)\
**Post date:** [October 25, 2019, 4:16am UTC](https://discuss.elastic.co/t/get-value-from-message-and-put-it-into-new-field/205045/3 "2019-10-25T04:16:34Z")

</div>

Thank you very much 😃 that was what i was looking.

But i have one more problem now, when i want to create fields which i will then map to geo\_point like below i get in kibana diffrent message, but when i remove to convert to float, message is ok :

```
	if [service][name] == "XXX" {
grok { match => { "message" => ["Longitude:(?<Longitude>[0-9]+,[0-9]+)*", "Latitude:(?<Latitude>[0-9]+,[0-9]+)*" ] } break_on_match => false }
mutate{ gsub => ["Latitude", ",", ".", "Longitude", ",", "."] }

mutate {
copy => {
  "Latitude" => "[XXXLocation][Latitude]"
  "Longitude" => "[XXXLocation][Longitude]"
}
}
mutate {
	convert => {"[XXXLocation][Latitude]" => "float" }}

mutate {
	convert => {"[XXXLocation][Longitude]" => "float" }}

}

```

what is going on ?

Ok i get it. Change to that works.

```
mutate {
	convert => {"[XXXLocation][Lat]" => "float" }}

mutate {
	convert => {"[XXXLocation][Lon]" => "float" }}
```

---

<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:** [November 22, 2019, 4:16am UTC](https://discuss.elastic.co/t/get-value-from-message-and-put-it-into-new-field/205045/4 "2019-11-22T04:16:36Z")

</div>

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