<?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 do I match a field to a variable? in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/How-do-I-match-a-field-to-a-variable/m-p/204375#M59361</link>
    <description>&lt;P&gt;You should click "Accept" to close out the question.&lt;/P&gt;</description>
    <pubDate>Sat, 24 Oct 2015 14:56:41 GMT</pubDate>
    <dc:creator>woodcock</dc:creator>
    <dc:date>2015-10-24T14:56:41Z</dc:date>
    <item>
      <title>How do I match a field to a variable?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-do-I-match-a-field-to-a-variable/m-p/204372#M59358</link>
      <description>&lt;P&gt;I've got a query that will have a string passed into it. In this case, it's "2-Low". I need to parse out the number and match that to rows with a field called 'score' containing the same value.&lt;/P&gt;

&lt;P&gt;Strangely enough, this query isn't returning results (there is definitely matching data):&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;index=someindex | parser | eval ar = split("2-Low","-") | eval tl = mvindex(ar, 0) | search score = tl
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;As a sanity check, if I try this to make sure the string manipulation worked, I get the number "2" as expected.&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;index=someindex | parser | eval ar = split("2-Low","-") | eval tl = mvindex(ar, 0) | fields tl
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Any thoughts on what I might not be doing correctly?&lt;/P&gt;</description>
      <pubDate>Fri, 23 Oct 2015 13:46:19 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-do-I-match-a-field-to-a-variable/m-p/204372#M59358</guid>
      <dc:creator>kkatzgraukeyw</dc:creator>
      <dc:date>2015-10-23T13:46:19Z</dc:date>
    </item>
    <item>
      <title>Re: How do I match a field to a variable?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-do-I-match-a-field-to-a-variable/m-p/204373#M59359</link>
      <description>&lt;P&gt;The problem is that you are using &lt;CODE&gt;search&lt;/CODE&gt; instead of &lt;CODE&gt;where&lt;/CODE&gt;.  The &lt;CODE&gt;search&lt;/CODE&gt; command ALWAYS understands the Right-Hand-Value to be a string-literal whereas &lt;CODE&gt;where&lt;/CODE&gt; presumes the RHV to be a fieldname and switches to treating it as a string-literal only if you force it to, such as by enclosing it in double-quotes.&lt;/P&gt;</description>
      <pubDate>Fri, 23 Oct 2015 14:33:34 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-do-I-match-a-field-to-a-variable/m-p/204373#M59359</guid>
      <dc:creator>woodcock</dc:creator>
      <dc:date>2015-10-23T14:33:34Z</dc:date>
    </item>
    <item>
      <title>Re: How do I match a field to a variable?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-do-I-match-a-field-to-a-variable/m-p/204374#M59360</link>
      <description>&lt;P&gt;Perfect. Thanks for the explanation!&lt;/P&gt;</description>
      <pubDate>Fri, 23 Oct 2015 17:08:55 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-do-I-match-a-field-to-a-variable/m-p/204374#M59360</guid>
      <dc:creator>kkatzgraukeyw</dc:creator>
      <dc:date>2015-10-23T17:08:55Z</dc:date>
    </item>
    <item>
      <title>Re: How do I match a field to a variable?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-do-I-match-a-field-to-a-variable/m-p/204375#M59361</link>
      <description>&lt;P&gt;You should click "Accept" to close out the question.&lt;/P&gt;</description>
      <pubDate>Sat, 24 Oct 2015 14:56:41 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-do-I-match-a-field-to-a-variable/m-p/204375#M59361</guid>
      <dc:creator>woodcock</dc:creator>
      <dc:date>2015-10-24T14:56:41Z</dc:date>
    </item>
    <item>
      <title>Re: How do I match a field to a variable?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-do-I-match-a-field-to-a-variable/m-p/204376#M59362</link>
      <description>&lt;P&gt;&lt;CODE&gt;where&lt;/CODE&gt; does &lt;STRONG&gt;NOT&lt;/STRONG&gt; switch to treating a fieldname as a string literal if that field does not exist. Doing so would be terrible. Example:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| stats count | eval field = "foo" | where field = "foo"
| stats count | eval field = "foo" | where field = foo
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;By your reasoning, both searches should keep the one event generated by the &lt;CODE&gt;stats&lt;/CODE&gt;. However, the field &lt;CODE&gt;foo&lt;/CODE&gt; does not exist, hence it's comparing &lt;CODE&gt;field&lt;/CODE&gt; to &lt;CODE&gt;null()&lt;/CODE&gt; yielding false and dropping the event. This is the only sane behaviour imaginable.&lt;/P&gt;

&lt;P&gt;Additionally, I would recommend against enclosing RHS fields in dollar signs because that would break when included in dashboards - those would then treat the dollar-sign-fieldname as a form token. Instead, enclose the field name in single quotes as documented here: &lt;A href="http://docs.splunk.com/Documentation/Splunk/6.3.1/SearchReference/Eval#Required_arguments"&gt;http://docs.splunk.com/Documentation/Splunk/6.3.1/SearchReference/Eval#Required_arguments&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Sat, 05 Dec 2015 14:40:07 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-do-I-match-a-field-to-a-variable/m-p/204376#M59362</guid>
      <dc:creator>martin_mueller</dc:creator>
      <dc:date>2015-12-05T14:40:07Z</dc:date>
    </item>
    <item>
      <title>Re: How do I match a field to a variable?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-do-I-match-a-field-to-a-variable/m-p/204377#M59363</link>
      <description>&lt;P&gt;You are correct, I have adjusted my answer to reflect the more correct nuance.&lt;/P&gt;</description>
      <pubDate>Sat, 05 Dec 2015 17:09:19 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-do-I-match-a-field-to-a-variable/m-p/204377#M59363</guid>
      <dc:creator>woodcock</dc:creator>
      <dc:date>2015-12-05T17:09:19Z</dc:date>
    </item>
  </channel>
</rss>

