<?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: How to iterate over the values of a complex field? in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/How-to-iterate-over-the-values-of-a-complex-field/m-p/626672#M217817</link>
    <description>&lt;P&gt;Here's an example that uses foreach to iterate through the keys/values within somefield.&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;| makeresults
| eval _raw="{\"some_field\": {
\"key1\": 10,
\"key2\": 20,
\"key3\": 5,
\"key4\": 77,
\"key5\": 33,
}
}"
| spath
| foreach some_field.* [
  | eval max=max('&amp;lt;&amp;lt;FIELD&amp;gt;&amp;gt;', max), max_field_key=if('&amp;lt;&amp;lt;FIELD&amp;gt;&amp;gt;'=max, "&amp;lt;&amp;lt;MATCHSTR&amp;gt;&amp;gt;", max_field_key)
]&lt;/LI-CODE&gt;&lt;P&gt;Note that if there are duplicate values, it will take the last field name as the max_field_key.&lt;/P&gt;&lt;P&gt;Anyway, hope this helps.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Tue, 10 Jan 2023 22:56:12 GMT</pubDate>
    <dc:creator>bowesmana</dc:creator>
    <dc:date>2023-01-10T22:56:12Z</dc:date>
    <item>
      <title>How to iterate over the values of a complex field?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-iterate-over-the-values-of-a-complex-field/m-p/626669#M217815</link>
      <description>&lt;P&gt;The event has a field:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;{
...
some_field: {
 key1: value1
 key2: value2
}
...
}&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;How to iterate over the values of "some_field" field?&lt;/P&gt;&lt;P&gt;For example I need to get max value.&lt;/P&gt;&lt;P&gt;I need something like this:&lt;/P&gt;&lt;P&gt;... | eval filed_max_value=max(map_values(some_field))&lt;/P&gt;&lt;P&gt;For map_value I get error:&amp;nbsp;&lt;SPAN&gt;Error in 'EvalCommand': The 'map_values' function is unsupported or undefined.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;Could you also explain how to use&amp;nbsp;&lt;A href="https://docs.splunk.com/Documentation/DSP/1.3.1/FunctionReference/Map#:~:text=some_value%22%5D%2C%20map%3A%20attributes)%20%7C...%3B-,map_values(input),-Returns%20a%20list" target="_self"&gt;map_keys and map_values functions&lt;/A&gt;&amp;nbsp;?&lt;/P&gt;</description>
      <pubDate>Tue, 10 Jan 2023 22:11:28 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-iterate-over-the-values-of-a-complex-field/m-p/626669#M217815</guid>
      <dc:creator>Evgenii</dc:creator>
      <dc:date>2023-01-10T22:11:28Z</dc:date>
    </item>
    <item>
      <title>Re: How to iterate over the values of a complex field?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-iterate-over-the-values-of-a-complex-field/m-p/626672#M217817</link>
      <description>&lt;P&gt;Here's an example that uses foreach to iterate through the keys/values within somefield.&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;| makeresults
| eval _raw="{\"some_field\": {
\"key1\": 10,
\"key2\": 20,
\"key3\": 5,
\"key4\": 77,
\"key5\": 33,
}
}"
| spath
| foreach some_field.* [
  | eval max=max('&amp;lt;&amp;lt;FIELD&amp;gt;&amp;gt;', max), max_field_key=if('&amp;lt;&amp;lt;FIELD&amp;gt;&amp;gt;'=max, "&amp;lt;&amp;lt;MATCHSTR&amp;gt;&amp;gt;", max_field_key)
]&lt;/LI-CODE&gt;&lt;P&gt;Note that if there are duplicate values, it will take the last field name as the max_field_key.&lt;/P&gt;&lt;P&gt;Anyway, hope this helps.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 10 Jan 2023 22:56:12 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-iterate-over-the-values-of-a-complex-field/m-p/626672#M217817</guid>
      <dc:creator>bowesmana</dc:creator>
      <dc:date>2023-01-10T22:56:12Z</dc:date>
    </item>
    <item>
      <title>How to iterate over the values of a complex field?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-iterate-over-the-values-of-a-complex-field/m-p/626673#M217818</link>
      <description>&lt;P&gt;Also, those functions you reference are from DSP, not Splunk.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 10 Jan 2023 23:01:15 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-iterate-over-the-values-of-a-complex-field/m-p/626673#M217818</guid>
      <dc:creator>bowesmana</dc:creator>
      <dc:date>2023-01-10T23:01:15Z</dc:date>
    </item>
    <item>
      <title>Re: How to iterate over the values of a complex field?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-iterate-over-the-values-of-a-complex-field/m-p/626844#M217855</link>
      <description>&lt;P&gt;Magic with&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;spath | foreach some_field.*&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;works.&lt;/P&gt;&lt;P&gt;Thanks a lot!&lt;/P&gt;</description>
      <pubDate>Wed, 11 Jan 2023 19:42:26 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-iterate-over-the-values-of-a-complex-field/m-p/626844#M217855</guid>
      <dc:creator>Evgenii</dc:creator>
      <dc:date>2023-01-11T19:42:26Z</dc:date>
    </item>
  </channel>
</rss>

