Splunk Search

Field Aliases

HeinzWaescher
Motivator

Hi,

I want to configure some field aliases. I want to add an alias C for the fields A & B.
I've done this in the settings, but in the search it only works for field A. Is it not possible to set one alias for 2 different fields?

Best
Heinz

Tags (2)
0 Karma

HeinzWaescher
Motivator

Users can appear in both fields. I would like to have a way to create stats about distinct users. That's why I wanted to set two aliases:

A=C
B=C

Then I would have to deal only with one field (C) in the search.

PS: Next to that, I don't know how to handle a search for distinct user over 2 fields 😉

0 Karma

HeinzWaescher
Motivator

Ich glaube um das Problem zu umgehen funktionert folgendes:

| eval A_joined = mvjoin(A, ",")
| eval B_joined = mvjoin(B, ",")
| eval C = A_joined + "," + B_joined
| makemv delim="," C | stats dc(C), dc(A), dc(B)

Sieht von den Ergebnissen her auf den ersten Blick besser aus. Muss ich aber noch in ein paar Richtungen testen.

0 Karma

martin_mueller
SplunkTrust
SplunkTrust

Na klar - wenn A oder B multi-value fields sind, geht die Stringkonkatenation aus meinem Beispiel nicht.

0 Karma

HeinzWaescher
Motivator

Genau, ich habe es mal überprüft mit:

...| search A=* AND B=* | eval sst=A."###".B | table sst

Einige Ergebnisfelder sehen so aus: 26828###15624
Andere hingegen sind leer, obwohl sie es nicht sein dürften.

Es scheinen die Felder leer zu sein, wenn im Event mehrere Male das Feld A oder mehrere Male das Feld B auftritt.

0 Karma

martin_mueller
SplunkTrust
SplunkTrust

dc(C) < dc(A) darf in der Tat nicht sein - aber da läuft vorher was falsch, vermutlich beim Befüllen von C.

0 Karma

HeinzWaescher
Motivator

Hast recht, die Zählung ist richtig. Ich habe mir das erzeugte "foo" (oder C in meinem Beispiel) Feld exportiert und extern gezählt.
Irgendetwas mache ich aber noch falsch, bzw. die Einträge in "foo" (C) sind nicht zielführend. Das Ergebniss dc(foo) (bzw. dc(c)) ist geringer als dc(A) und auch geringer als dc(B). Das darf ja nicht sein.

0 Karma

martin_mueller
SplunkTrust
SplunkTrust

Das ist der Plan. Example:

| stats count as foo | eval foo = "1-1,2-3,3-5" | makemv foo delim="," | mvexpand foo | makemv foo delim="-" | appendpipe [stats dc(foo)]

Result:

foo   dc(foo)
1
1

2
3

3
5

.     4

dc(foo) ist korrekt, denn foo enthält 1,2,3,5 - also distinct count = 4.

0 Karma

HeinzWaescher
Motivator

Hi Martin,

ich wechsel mal die Sprache, macht's etwas einfacher 😉

Deinen Ansatz kann ich soweit nachvollziehen, allerdings scheint dc(sst) nicht wie gewünscht zu funktionieren. Soll hierbei jedes einzelne Element der multivalue fields gezählt werden?

Meine Suche:

| eval C=A."###".B | makemv C delim="###" | stats dc(A), dc(B), dc(C)

Außerdem ist "sst" oft leer.

0 Karma

martin_mueller
SplunkTrust
SplunkTrust

That's beyond an alias. You basically want to merge A and B into a multi-value field.

You can eval your way there though, like this:

index=_internal | eval sst = source."###".sourcetype | makemv sst delim="###" | stats dc(source) dc(sourcetype) dc(sst)

Imagine source is A, sourcetype is B, and sst is C. That eval should be includeable in a calculated field, but probably not the makemv. You can go macro of course.

0 Karma

HeinzWaescher
Motivator

I thought I can collect all users from A & B in this field and use dc(C) to get the total distinct usercount.

But it doesn't make sense via an alias, because there would be more than 1 value for the field C in each event?!

In the end, I'm just looking for way to dc(users). These users can appear in the fields A & B.

0 Karma

martin_mueller
SplunkTrust
SplunkTrust

If A and B exist in one event then my C will eval to A.

What should the value of C be in this case? (See my comment on your question)

0 Karma

HeinzWaescher
Motivator

I tried this out, but dc(c) is always equal to dc(a).
The fields A & B can both appear in one event. So I think that's why this command is just using the users of the field A.

0 Karma

martin_mueller
SplunkTrust
SplunkTrust

You could do this:

... | eval C = coalesce(A, B) | stats dc(C)

"Use A if exists, else use B". That can be stored in a calculated field if you like.

0 Karma

martin_mueller
SplunkTrust
SplunkTrust

What is the value of C supposed to be if both A and B exist?

0 Karma
Get Updates on the Splunk Community!

Introducing Splunk Enterprise 9.2

WATCH HERE! Watch this Tech Talk to learn about the latest features and enhancements shipped in the new Splunk ...

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 ...

Routing logs with Splunk OTel Collector for Kubernetes

The Splunk Distribution of the OpenTelemetry (OTel) Collector is a product that provides a way to ingest ...