<?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 return a single value from a subsearch into eval in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/How-to-return-a-single-value-from-a-subsearch-into-eval/m-p/133577#M36479</link>
    <description>&lt;P&gt;Another hint  &lt;CODE&gt;... | return $ip | format ]&lt;/CODE&gt;&lt;/P&gt;</description>
    <pubDate>Fri, 24 Jan 2020 15:25:11 GMT</pubDate>
    <dc:creator>evelenke</dc:creator>
    <dc:date>2020-01-24T15:25:11Z</dc:date>
    <item>
      <title>How to return a single value from a subsearch into eval</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-return-a-single-value-from-a-subsearch-into-eval/m-p/133571#M36473</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;

&lt;P&gt;I'm trying to calculate a value through some lookup statements and then put that value into a variable using eval. I've been googling and reading documentation for a while now and "return" seems the way to go, but I can't get it to work.&lt;/P&gt;

&lt;P&gt;Basically what I want to do is:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;somesearch | eval somevar=[ subsearch | lookup | return $lookupresult ]
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;But whatever I try, I never get the "somevar" field in my resulting events.&lt;/P&gt;

&lt;P&gt;I tried boiling it down to a very simple dummy query to test this, but even this does not return any "aatest" field in the resulting event:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;index=main | head 1 | eval aatest=[ search index=main | head 1 | eval ip="test" | return $ip ]
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;As I understand it, this should just return the "aatest" field with value "test" in the 1 resulting event, no?&lt;/P&gt;

&lt;P&gt;Thanks!&lt;/P&gt;</description>
      <pubDate>Tue, 02 Jun 2015 08:17:56 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-return-a-single-value-from-a-subsearch-into-eval/m-p/133571#M36473</guid>
      <dc:creator>Sloefke</dc:creator>
      <dc:date>2015-06-02T08:17:56Z</dc:date>
    </item>
    <item>
      <title>Re: How to return a single value from a subsearch into eval</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-return-a-single-value-from-a-subsearch-into-eval/m-p/133572#M36474</link>
      <description>&lt;P&gt;surprising! I think it should work. Here s an example which is working perfectly&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;index=_internal |eval aaa=[search index=_internal sourcetype="splunkd"|head 1|eval c2="45555"|return $c2]
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;or&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;index=_internal |eval aaa= 1 + [search index=_internal sourcetype="splunkd"|stats count as c1|return $c1]|table aaa
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 02 Jun 2015 09:15:42 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-return-a-single-value-from-a-subsearch-into-eval/m-p/133572#M36474</guid>
      <dc:creator>stephanefotso</dc:creator>
      <dc:date>2015-06-02T09:15:42Z</dc:date>
    </item>
    <item>
      <title>Re: How to return a single value from a subsearch into eval</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-return-a-single-value-from-a-subsearch-into-eval/m-p/133573#M36475</link>
      <description>&lt;P&gt;Your 2 tests worked for me as well, so I started looking a bit. Seems the only difference is the value of the returned variable, where you use an integer and I use a string. And indeed, this does work:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;index=main | head 1 | eval aatest=[ search index=main | head 1 | eval ip="123" | return $ip ]
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;while this still doesn't:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;index=main | head 1 | eval aatest=[ search index=main | head 1 | eval ip="test" | return $ip ]
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;What the? return should be able to return strings, no? &lt;span class="lia-unicode-emoji" title=":confused_face:"&gt;😕&lt;/span&gt;&lt;/P&gt;

&lt;P&gt;Edit: my guess is that the return search does return a string, but it can't be mapped into the "aatest" variable without quotes? Now to try to fix that ...&lt;/P&gt;</description>
      <pubDate>Tue, 02 Jun 2015 09:23:31 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-return-a-single-value-from-a-subsearch-into-eval/m-p/133573#M36475</guid>
      <dc:creator>Sloefke</dc:creator>
      <dc:date>2015-06-02T09:23:31Z</dc:date>
    </item>
    <item>
      <title>Re: How to return a single value from a subsearch into eval</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-return-a-single-value-from-a-subsearch-into-eval/m-p/133574#M36476</link>
      <description>&lt;P&gt;hum! That's a really problem! i'm troubleshooting the issue.&lt;/P&gt;</description>
      <pubDate>Tue, 02 Jun 2015 10:47:45 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-return-a-single-value-from-a-subsearch-into-eval/m-p/133574#M36476</guid>
      <dc:creator>stephanefotso</dc:creator>
      <dc:date>2015-06-02T10:47:45Z</dc:date>
    </item>
    <item>
      <title>Re: How to return a single value from a subsearch into eval</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-return-a-single-value-from-a-subsearch-into-eval/m-p/133575#M36477</link>
      <description>&lt;P&gt;I've been searching some more as well, but I can't find a way to 'convert' the subsearch to something eval would recognize as a string &lt;span class="lia-unicode-emoji" title=":confused_face:"&gt;😕&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 03 Jun 2015 08:36:19 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-return-a-single-value-from-a-subsearch-into-eval/m-p/133575#M36477</guid>
      <dc:creator>Sloefke</dc:creator>
      <dc:date>2015-06-03T08:36:19Z</dc:date>
    </item>
    <item>
      <title>Re: How to return a single value from a subsearch into eval</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-return-a-single-value-from-a-subsearch-into-eval/m-p/133576#M36478</link>
      <description>&lt;P&gt;Problem solved (thanks to distributor support)! To pass strings, the quotes need to be added to the variable in the subsearch (which makes sense thinking of it):&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;index=main | head 1 | eval aatest=[ search index=main | head 1 | eval ip="\"test\"" | return $ip ]
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 03 Jun 2015 13:30:30 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-return-a-single-value-from-a-subsearch-into-eval/m-p/133576#M36478</guid>
      <dc:creator>Sloefke</dc:creator>
      <dc:date>2015-06-03T13:30:30Z</dc:date>
    </item>
    <item>
      <title>Re: How to return a single value from a subsearch into eval</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-return-a-single-value-from-a-subsearch-into-eval/m-p/133577#M36479</link>
      <description>&lt;P&gt;Another hint  &lt;CODE&gt;... | return $ip | format ]&lt;/CODE&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 24 Jan 2020 15:25:11 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-return-a-single-value-from-a-subsearch-into-eval/m-p/133577#M36479</guid>
      <dc:creator>evelenke</dc:creator>
      <dc:date>2020-01-24T15:25:11Z</dc:date>
    </item>
    <item>
      <title>Re: How to return a single value from a subsearch into eval</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-return-a-single-value-from-a-subsearch-into-eval/m-p/595367#M207211</link>
      <description>&lt;P&gt;weird, the solution didn't worked out for me; it returned the string "ip" instead of the expected ip field value.&lt;/P&gt;&lt;P&gt;But this slightly adapted variant worked for me:&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;index=main | head 1 | eval aatest=[ search index=main | head 1 | eval ip="\"" + test + "\"" | return $ip ]&lt;/PRE&gt;</description>
      <pubDate>Tue, 26 Apr 2022 10:20:48 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-return-a-single-value-from-a-subsearch-into-eval/m-p/595367#M207211</guid>
      <dc:creator>mhergh</dc:creator>
      <dc:date>2022-04-26T10:20:48Z</dc:date>
    </item>
    <item>
      <title>Re: How to return a single value from a subsearch into eval</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-return-a-single-value-from-a-subsearch-into-eval/m-p/681377#M232833</link>
      <description>&lt;P&gt;Hi&lt;/P&gt;&lt;P&gt;this is the way if you want to return value of some field from inner search. It seems that it excepting those " marks outside of value.&amp;nbsp;&lt;/P&gt;&lt;P&gt;r. Ismo&lt;/P&gt;</description>
      <pubDate>Wed, 20 Mar 2024 12:39:33 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-return-a-single-value-from-a-subsearch-into-eval/m-p/681377#M232833</guid>
      <dc:creator>isoutamo</dc:creator>
      <dc:date>2024-03-20T12:39:33Z</dc:date>
    </item>
  </channel>
</rss>

