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 😉
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.
Na klar - wenn A oder B multi-value fields sind, geht die Stringkonkatenation aus meinem Beispiel nicht.
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.
dc(C) < dc(A)
darf in der Tat nicht sein - aber da läuft vorher was falsch, vermutlich beim Befüllen von C.
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.
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.
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.
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.
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.
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)
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.
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.
What is the value of C supposed to be if both A and B exist?