Splunk Search

Why doesn't replace work on a nested field?

YatMan
Explorer

Sample event

 

{ 
    durationMs:  83  
    properties:  { 
        url:  https://mywebsite/v1/organization/41547/buildings
    } 
   correlationId: e581d476-fa5f-4023-a53e-53d6e06734ae
}

 


I want to replace the ids into
https://mywebsite/v1/organization/{id}/buildings

I tried {base search string} | eval endpoint=replace(properties.url, "\d+", "{id}") | stats by endpoint 
This return no result, but if I try other coorelationId field on the root level, {base search string} | eval endpoint=replace(coorelationId, "\d+", "{id}") | stats by endpoint  

This return what I expected
endpoint                   |   (other fields)
adb{id}f{id}-{id}fd{id}-{id}-a{id}b-{id}c{id}f{id}d | (other fields)
aea{id}e{id}c-fcdc-{id}-a{id}-{id}a{id}bfe{id}ee{id} | (other fields)

Why replace doesn't work on nested field?

Labels (1)
0 Karma
1 Solution

ITWhisperer
SplunkTrust
SplunkTrust

Field names with dots in or other special characters need to be in single quotes. Try this

| eval endpoint=replace('properties.url', "\d+", "{id}")

View solution in original post

ITWhisperer
SplunkTrust
SplunkTrust

Field names with dots in or other special characters need to be in single quotes. Try this

| eval endpoint=replace('properties.url', "\d+", "{id}")

YatMan
Explorer

this single quote solution works well. thank you.
It would be helpful if you guys can add an example in the document, thanks! https://docs.splunk.com/Documentation/Splunk/latest/SearchReference/Replace#Syntax

0 Karma

johnhuang
Motivator

Splunk doesn't like fieldnames with special characters like periods.

 

| rename properties.url AS endpoint
| rex field=endpoint mode=sed "s/\/\d+\//\/{id}\//"

 

0 Karma
Get Updates on the Splunk Community!

Webinar Recap | Revolutionizing IT Operations: The Transformative Power of AI and ML ...

The Transformative Power of AI and ML in Enhancing Observability   In the realm of IT operations, the ...

.conf24 | Registration Open!

Hello, hello! I come bearing good news: Registration for .conf24 is now open!   conf is Splunk’s rad annual ...

ICYMI - Check out the latest releases of Splunk Edge Processor

Splunk is pleased to announce the latest enhancements to Splunk Edge Processor.  HEC Receiver authorization ...