<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Extract some key-value pairs in Splunk Enterprise</title>
    <link>https://community.splunk.com/t5/Splunk-Enterprise/Extract-some-key-value-pairs/m-p/711510#M21651</link>
    <description>&lt;P&gt;Hi&lt;/P&gt;&lt;P&gt;In the end, I used this however it was not clear to me why I did not need to reference the newly created X_Mr. I could go straight to MR&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;source="trace_Marketing_Bench_31032016_17_cff762901d1eff01766119738a9218e2*.jsonl" host="TEST2" index="murex_logs" sourcetype="Market_Risk_DT" "**strategy**" 920e1021406277a9 
| spath resourceSpans{}.scopeSpans{}.spans{}.attributes{} output=attributes 
| mvexpand attributes 
| spath input=attributes 
| eval X_{key}=coalesce('value.doubleValue', 'value.stringValue') 
| stats values(X_*) as * by _time 
| stats sum(mr_batch_load_cpu_time) as batch_load_cpu_time sum(mr_batch_load_time) as batch_load_time sum(mr_batch_compute_time) as mr_batch_compute_time sum(mr_batch_compute_cpu_time) as mr_batch_compute_cpu_time by mr_strategy&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;This created the below table that I was looking to do&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="robertlynch2020_0-1739466250315.png" style="width: 400px;"&gt;&lt;img src="https://community.splunk.com/t5/image/serverpage/image-id/34484iF3FA56817ABE0ABF/image-size/medium?v=v2&amp;amp;px=400" role="button" title="robertlynch2020_0-1739466250315.png" alt="robertlynch2020_0-1739466250315.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;What I don't understand is at this point I can only see the new fields X_mr&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="robertlynch2020_1-1739466481902.png" style="width: 400px;"&gt;&lt;img src="https://community.splunk.com/t5/image/serverpage/image-id/34485i8C6FBB1C1632D140/image-size/medium?v=v2&amp;amp;px=400" role="button" title="robertlynch2020_1-1739466481902.png" alt="robertlynch2020_1-1739466481902.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;I added in a "| stats values(X_*) as * by _time" and we are back to the original - I don't get that.&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="robertlynch2020_2-1739466589340.png" style="width: 400px;"&gt;&lt;img src="https://community.splunk.com/t5/image/serverpage/image-id/34486i91CEA4FD6764567D/image-size/medium?v=v2&amp;amp;px=400" role="button" title="robertlynch2020_2-1739466589340.png" alt="robertlynch2020_2-1739466589340.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Thu, 13 Feb 2025 17:11:19 GMT</pubDate>
    <dc:creator>robertlynch2020</dc:creator>
    <dc:date>2025-02-13T17:11:19Z</dc:date>
    <item>
      <title>Extract some key-value pairs</title>
      <link>https://community.splunk.com/t5/Splunk-Enterprise/Extract-some-key-value-pairs/m-p/711409#M21626</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am looking to extract some key-value pairs, for each event.&lt;/P&gt;&lt;P&gt;I have data that always has&amp;nbsp;resourceSpans{}.scopeSpans{}.spans{}.attributes{}.key&lt;/P&gt;&lt;P&gt;but it might have&amp;nbsp;resourceSpans{}.scopeSpans{}.spans{}.attributes{}.value.&lt;STRONG&gt;doubleValue&lt;/STRONG&gt; or&amp;nbsp;resourceSpans{}.scopeSpans{}.spans{}.attributes{}.value.&lt;STRONG&gt;stringValue&lt;/STRONG&gt;.&lt;/P&gt;&lt;P&gt;I want to use them to run stats commands on them. So I was looking to extract each&amp;nbsp;&lt;/P&gt;&lt;P&gt;Key |&amp;nbsp;&lt;STRONG&gt;doubleValue&lt;/STRONG&gt;&amp;nbsp;or&amp;nbsp;&lt;STRONG&gt;stringValue&amp;nbsp;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;and then use them&lt;/P&gt;&lt;P&gt;This is some of the data I have. We can see that&amp;nbsp;&lt;STRONG&gt;doubleValue&lt;/STRONG&gt;&amp;nbsp;and&amp;nbsp;&lt;STRONG&gt;stringValue&amp;nbsp; are mixed and can pop up anytime.&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="robertlynch2020_0-1739384652321.png" style="width: 400px;"&gt;&lt;img src="https://community.splunk.com/t5/image/serverpage/image-id/34475i98E317DC727735F9/image-size/medium?v=v2&amp;amp;px=400" role="button" title="robertlynch2020_0-1739384652321.png" alt="robertlynch2020_0-1739384652321.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;I have tried the following. But there is an issue&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;source="trace_Marketing_Bench_31032016_17_cff762901d1eff01766119738a9218e2.jsonl" host="TEST1" index="murex_logs" sourcetype="Market_Risk_DT" "**strategy**" 920e1021406277a9 
| spath "resourceSpans{}.scopeSpans{}.spans{}.attributes{}.value.stringValue" 
| spath "resourceSpans{}.scopeSpans{}.spans{}.attributes{}.value.doubleValue" 
| spath "resourceSpans{}.scopeSpans{}.spans{}.attributes{}.key" 
| eval output=mvzip('resourceSpans{}.scopeSpans{}.spans{}.attributes{}.value.stringValue','resourceSpans{}.scopeSpans{}.spans{}.attributes{}.key') | table output&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The order is not coming out correctly. In red, we can see that&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="robertlynch2020_1-1739384831277.png" style="width: 400px;"&gt;&lt;img src="https://community.splunk.com/t5/image/serverpage/image-id/34476i0393471F5A497D1F/image-size/medium?v=v2&amp;amp;px=400" role="button" title="robertlynch2020_1-1739384831277.png" alt="robertlynch2020_1-1739384831277.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;WARNING is with mr_batch_status, not&amp;nbsp;&lt;STRONG&gt;mr_batch_compute_cpu_time - &lt;/STRONG&gt;That is because they are both extracting independently and not synced to each other. How do I get them to extract the same?&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="robertlynch2020_2-1739385312952.png" style="width: 400px;"&gt;&lt;img src="https://community.splunk.com/t5/image/serverpage/image-id/34477i8D0192684D163F17/image-size/medium?v=v2&amp;amp;px=400" role="button" title="robertlynch2020_2-1739385312952.png" alt="robertlynch2020_2-1739385312952.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;SOme raw data&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;{"resourceSpans":[{"resource":{"attributes":[{"key":"telemetry.sdk.version","value":{"stringValue":"1.12.0"}},{"key":"telemetry.sdk.name","value":{"stringValue":"opentelemetry"}},{"key":"telemetry.sdk.language","value":{"stringValue":"cpp"}},{"key":"service.instance.id","value":{"stringValue":"00vptl2h"}},{"key":"service.namespace","value":{"stringValue":"MXMARKETRISK.SERVICE"}},{"key":"service.name","value":{"stringValue":"MXMARKETRISK.ENGINE.MX"}}]},"scopeSpans":[{"scope":{"name":"murex::tracing_backend::otel","version":"v1"},"spans":[{"traceId":"cff762901d1eff01766119738a9218e2","spanId":"71d94e8ebb30a3d5","parentSpanId":"920e1021406277a9","name":"fullreval_task","kind":"SPAN_KIND_INTERNAL","startTimeUnixNano":"1716379123221825454","endTimeUnixNano":"1716379155367858727","attributes":[{"key":"market_risk_span","value":{"stringValue":"true"}},{"key":"mr_batchId","value":{"stringValue":"440"}},{"key":"mr_batchType","value":{"stringValue":"Full Revaluation"}},{"key":"mr_bucketName","value":{"stringValue":"imccBucket#ALL_10_Reduced"}},{"key":"mr_jobDomain","value":{"stringValue":"Market Risk"}},{"key":"mr_jobId","value":{"stringValue":"Marketing_Bench | 31/03/2016 | 17"}},{"key":"mr_strategy","value":{"stringValue":"typo_Bond"}},{"key":"mr_uuid","value":{"stringValue":"b1ed4d3a-0e4d-4afa-ad39-7cf6a07c36a9"}},{"key":"mrb_batch_affinity","value":{"stringValue":"Marketing_Bench_run_Batch|Marketing_Bench|2016/03/31|17_FullReval0_00029"}},{"key":"mr_batch_compute_cpu_time","value":{"doubleValue":31.586568}},{"key":"mr_batch_compute_time","value":{"doubleValue":31.777}},{"key":"mr_batch_load_cpu_time","value":{"doubleValue":0.0}},{"key":"mr_batch_load_time","value":{"doubleValue":0.0}},{"key":"mr_batch_status","value":{"stringValue":"WARNING"}},{"key":"mr_batch_total_cpu_time","value":{"doubleValue":31.912966}},{"key":"mr_batch_total_time","value":{"doubleValue":32.14}}],"status":{}}]}]}]}&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 12 Feb 2025 18:39:27 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Enterprise/Extract-some-key-value-pairs/m-p/711409#M21626</guid>
      <dc:creator>robertlynch2020</dc:creator>
      <dc:date>2025-02-12T18:39:27Z</dc:date>
    </item>
    <item>
      <title>Re: Extract some key-value pairs</title>
      <link>https://community.splunk.com/t5/Splunk-Enterprise/Extract-some-key-value-pairs/m-p/711421#M21630</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://community.splunk.com/t5/user/viewprofilepage/user-id/141978"&gt;@robertlynch2020&lt;/a&gt;&amp;nbsp;&lt;BR /&gt;Is this what you are after? Ive loaded in your sample event to start with but you can replace this with the search for your events!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;| makeresults
| eval _raw="{\"resourceSpans\":[{\"resource\":{\"attributes\":[{\"key\":\"telemetry.sdk.version\",\"value\":{\"stringValue\":\"1.12.0\"}},{\"key\":\"telemetry.sdk.name\",\"value\":{\"stringValue\":\"opentelemetry\"}},{\"key\":\"telemetry.sdk.language\",\"value\":{\"stringValue\":\"cpp\"}},{\"key\":\"service.instance.id\",\"value\":{\"stringValue\":\"00vptl2h\"}},{\"key\":\"service.namespace\",\"value\":{\"stringValue\":\"MXMARKETRISK.SERVICE\"}},{\"key\":\"service.name\",\"value\":{\"stringValue\":\"MXMARKETRISK.ENGINE.MX\"}}]},\"scopeSpans\":[{\"scope\":{\"name\":\"murex::tracing_backend::otel\",\"version\":\"v1\"},\"spans\":[{\"traceId\":\"cff762901d1eff01766119738a9218e2\",\"spanId\":\"71d94e8ebb30a3d5\",\"parentSpanId\":\"920e1021406277a9\",\"name\":\"fullreval_task\",\"kind\":\"SPAN_KIND_INTERNAL\",\"startTimeUnixNano\":\"1716379123221825454\",\"endTimeUnixNano\":\"1716379155367858727\",\"attributes\":[{\"key\":\"market_risk_span\",\"value\":{\"stringValue\":\"true\"}},{\"key\":\"mr_batchId\",\"value\":{\"stringValue\":\"440\"}},{\"key\":\"mr_batchType\",\"value\":{\"stringValue\":\"Full Revaluation\"}},{\"key\":\"mr_bucketName\",\"value\":{\"stringValue\":\"imccBucket#ALL_10_Reduced\"}},{\"key\":\"mr_jobDomain\",\"value\":{\"stringValue\":\"Market Risk\"}},{\"key\":\"mr_jobId\",\"value\":{\"stringValue\":\"Marketing_Bench | 31/03/2016 | 17\"}},{\"key\":\"mr_strategy\",\"value\":{\"stringValue\":\"typo_Bond\"}},{\"key\":\"mr_uuid\",\"value\":{\"stringValue\":\"b1ed4d3a-0e4d-4afa-ad39-7cf6a07c36a9\"}},{\"key\":\"mrb_batch_affinity\",\"value\":{\"stringValue\":\"Marketing_Bench_run_Batch|Marketing_Bench|2016/03/31|17_FullReval0_00029\"}},{\"key\":\"mr_batch_compute_cpu_time\",\"value\":{\"doubleValue\":31.586568}},{\"key\":\"mr_batch_compute_time\",\"value\":{\"doubleValue\":31.777}},{\"key\":\"mr_batch_load_cpu_time\",\"value\":{\"doubleValue\":0.0}},{\"key\":\"mr_batch_load_time\",\"value\":{\"doubleValue\":0.0}},{\"key\":\"mr_batch_status\",\"value\":{\"stringValue\":\"WARNING\"}},{\"key\":\"mr_batch_total_cpu_time\",\"value\":{\"doubleValue\":31.912966}},{\"key\":\"mr_batch_total_time\",\"value\":{\"doubleValue\":32.14}}],\"status\":{}}]}]}]}" 
| eval eventKey=md5(_raw) 
| eval attributes=json_array_to_mv(json_extract(_raw,"resourceSpans{}.scopeSpans{}.spans{}.attributes")) 
| mvexpand attributes 
| eval attribute_key=json_extract(attributes,"key") 
| eval attribute_val=coalesce(json_extract(json_extract(attributes,"value"),"stringValue"),json_extract(json_extract(attributes,"value"),"doubleValue"))
| eval  extracted_{attribute_key}=attribute_val
| stats values(extracted_*) as * by eventKey&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Basically you're doing&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;| eval eventKey=md5(_raw) 
| eval attributes=json_array_to_mv(json_extract(_raw,"resourceSpans{}.scopeSpans{}.spans{}.attributes")) 
| mvexpand attributes 
| eval attribute_key=json_extract(attributes,"key") 
| eval attribute_val=coalesce(json_extract(json_extract(attributes,"value"),"stringValue"),json_extract(json_extract(attributes,"value"),"doubleValue"))
| eval  extracted_{attribute_key}=attribute_val
| stats values(extracted_*) as * by eventKey&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Please let me know how you get on and consider accepting this answer or adding karma this answer if it has helped.&lt;BR /&gt;Regards&lt;/P&gt;&lt;P&gt;Will&lt;/P&gt;</description>
      <pubDate>Wed, 12 Feb 2025 22:33:21 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Enterprise/Extract-some-key-value-pairs/m-p/711421#M21630</guid>
      <dc:creator>livehybrid</dc:creator>
      <dc:date>2025-02-12T22:33:21Z</dc:date>
    </item>
    <item>
      <title>Re: Extract some key-value pairs</title>
      <link>https://community.splunk.com/t5/Splunk-Enterprise/Extract-some-key-value-pairs/m-p/711433#M21632</link>
      <description>&lt;P&gt;Try something like this&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;| spath resourceSpans{}.scopeSpans{}.spans{}.attributes{} output=attributes
| mvexpand attributes
| spath input=attributes
| eval X_{key}=coalesce('value.doubleValue', 'value.stringValue')
| stats values(X_*) as * by _raw&lt;/LI-CODE&gt;</description>
      <pubDate>Wed, 12 Feb 2025 23:53:58 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Enterprise/Extract-some-key-value-pairs/m-p/711433#M21632</guid>
      <dc:creator>ITWhisperer</dc:creator>
      <dc:date>2025-02-12T23:53:58Z</dc:date>
    </item>
    <item>
      <title>Re: Extract some key-value pairs</title>
      <link>https://community.splunk.com/t5/Splunk-Enterprise/Extract-some-key-value-pairs/m-p/711510#M21651</link>
      <description>&lt;P&gt;Hi&lt;/P&gt;&lt;P&gt;In the end, I used this however it was not clear to me why I did not need to reference the newly created X_Mr. I could go straight to MR&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;source="trace_Marketing_Bench_31032016_17_cff762901d1eff01766119738a9218e2*.jsonl" host="TEST2" index="murex_logs" sourcetype="Market_Risk_DT" "**strategy**" 920e1021406277a9 
| spath resourceSpans{}.scopeSpans{}.spans{}.attributes{} output=attributes 
| mvexpand attributes 
| spath input=attributes 
| eval X_{key}=coalesce('value.doubleValue', 'value.stringValue') 
| stats values(X_*) as * by _time 
| stats sum(mr_batch_load_cpu_time) as batch_load_cpu_time sum(mr_batch_load_time) as batch_load_time sum(mr_batch_compute_time) as mr_batch_compute_time sum(mr_batch_compute_cpu_time) as mr_batch_compute_cpu_time by mr_strategy&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;This created the below table that I was looking to do&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="robertlynch2020_0-1739466250315.png" style="width: 400px;"&gt;&lt;img src="https://community.splunk.com/t5/image/serverpage/image-id/34484iF3FA56817ABE0ABF/image-size/medium?v=v2&amp;amp;px=400" role="button" title="robertlynch2020_0-1739466250315.png" alt="robertlynch2020_0-1739466250315.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;What I don't understand is at this point I can only see the new fields X_mr&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="robertlynch2020_1-1739466481902.png" style="width: 400px;"&gt;&lt;img src="https://community.splunk.com/t5/image/serverpage/image-id/34485i8C6FBB1C1632D140/image-size/medium?v=v2&amp;amp;px=400" role="button" title="robertlynch2020_1-1739466481902.png" alt="robertlynch2020_1-1739466481902.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;I added in a "| stats values(X_*) as * by _time" and we are back to the original - I don't get that.&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="robertlynch2020_2-1739466589340.png" style="width: 400px;"&gt;&lt;img src="https://community.splunk.com/t5/image/serverpage/image-id/34486i91CEA4FD6764567D/image-size/medium?v=v2&amp;amp;px=400" role="button" title="robertlynch2020_2-1739466589340.png" alt="robertlynch2020_2-1739466589340.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 13 Feb 2025 17:11:19 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Enterprise/Extract-some-key-value-pairs/m-p/711510#M21651</guid>
      <dc:creator>robertlynch2020</dc:creator>
      <dc:date>2025-02-13T17:11:19Z</dc:date>
    </item>
    <item>
      <title>Re: Extract some key-value pairs</title>
      <link>https://community.splunk.com/t5/Splunk-Enterprise/Extract-some-key-value-pairs/m-p/711517#M21652</link>
      <description>&lt;LI-CODE lang="markup"&gt;| stats values(X_*) as * by _time&lt;/LI-CODE&gt;&lt;P&gt;This line removes all the other fields. You would need to add more fields to this if you want more fields to be kept.&lt;/P&gt;</description>
      <pubDate>Thu, 13 Feb 2025 18:18:22 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Enterprise/Extract-some-key-value-pairs/m-p/711517#M21652</guid>
      <dc:creator>ITWhisperer</dc:creator>
      <dc:date>2025-02-13T18:18:22Z</dc:date>
    </item>
  </channel>
</rss>

