Splunk Search

FieldAlias Setup

wildbill4
Path Finder

I'm trying to setup Fieldalias and not getting desire results. Here is what I have put into the props.conf file.

  FIELDALIAS = acct AS account
  FIELDALIAS = User_Name AS account

Am I missing something??

Thanks

Tags (2)
1 Solution

southeringtonp
Motivator

Your second FIELDALIAS statement will override the first.

Try adding an extension so that you have two unique entries:

FIELDALIAS-acct = acct AS account
FIELDALIAS-username = User_Name AS account

Alternately, you can have both aliases in a single line. If you go that route, you will still override any previously defined value for FIELDALIAS=, so it's still a good idea to add a qualifier as shown above.

View solution in original post

Dan
Splunk Employee
Splunk Employee

Unfortunately, field aliasing is one-to-one, and won't allow you to map many-to-one. The reason is that if orig_field doesn't exist, a blank value will be assigned to new_field.

Consider an event that has only the acct field. Both FIELDALIAS directives will be evaluated. Lexicographically, FIELDALIAS-acct runs first and successfully aliases acct as account. But when FIELDALIAS-username runs it finds no User_Name field, so the result is the account field will be blank.

There are two ways to work around this.

  1. Use props.conf:

    REPORT-alias_account = acct_as_account,User_Name_as_account
    

    and transforms.conf:

    [acct_as_account]
    SOURCE_KEY = acct
    REGEX = (?<account>.+)
    [User_Name_as_account]
    SOURCE_KEY = User_Name
    REGEX = (?<account>.+)
    
  2. Use the search language:

    | eval account= IF(ISNULL(acct),User_Name,acct)
    

southeringtonp
Motivator

Your second FIELDALIAS statement will override the first.

Try adding an extension so that you have two unique entries:

FIELDALIAS-acct = acct AS account
FIELDALIAS-username = User_Name AS account

Alternately, you can have both aliases in a single line. If you go that route, you will still override any previously defined value for FIELDALIAS=, so it's still a good idea to add a qualifier as shown above.

wildbill4
Path Finder

Thanks for the assistance

0 Karma

southeringtonp
Motivator

It will have to be in a stanza that matches the sourcetype (or host, or source) for which you want to set the field alias. Other than that, it doesn't matter as long as it's a unique entry as above. If it's non-unique, then you have to worry about precedence rules, since another entry could override it (possibly from a different app). Also, I'm assuming you're only trying to use it within the search app -- if you need it across multiple apps you'll need to check the permissions and make sure it's set to global.

0 Karma

wildbill4
Path Finder

Does it matter where in the props.conf file I input the FIELDALIAS information?

0 Karma
Get Updates on the Splunk Community!

Welcome to the Splunk Community!

(view in My Videos) We're so glad you're here! The Splunk Community is place to connect, learn, give back, and ...

Tech Talk | Elevating Digital Service Excellence: The Synergy of Splunk RUM & APM

Elevating Digital Service Excellence: The Synergy of Real User Monitoring and Application Performance ...

Adoption of RUM and APM at Splunk

    Unleash the power of Splunk Observability   Watch Now In this can't miss Tech Talk! The Splunk Growth ...