Need helpppppp


(souheil) #1

okey so i have a problem
i have a colon called EVENT, in this colon contains(failed,success,...) so i want to make a scripted field,
def k=0;
for (int i = 0; i < doc['event'].length; i++) {
if(doc['event'][i] == "failed"){
k+=1;
}
} return k;
but it always gives me k=1;
i thought i had a problem with the code so i changed planty of time, this is another example
def failed = ;
def tab = ['event'];
for (int i = 0; i < tab.length; i++) {
if( doc[tab[i]].value == "failed")
failed.add(doc[tab[i]].value)
}
def temp = 0;
for (def inc: failed) {
temp += inc;
}
//failed.add(temp);
return temp;
and always get 1, so to make sure if my code is correct or not i made a

return doc['event'].length;

i got 1 so i have like 3000 lignes but it gives me 1
any tips or solutions


(Marius Dragomir) #2

Hello,
From what I understand you're trying to count the number of events that are failed?
You can do this with a simple metric visualization, with a Split by Terms on the EVENT field.
As for the scripted field, you're getting 1 as the result because scripted fields only run in the context of a single document, so they can't access other documents.

If I was wrong in my assumption on how your data looks, please leave an example of a document here so I can help you.


(souheil) #3

yeah you re absolutly right, i got that at the end that it runs on a single document
i didn't want to uses visualization because my goal to have every user(with his id) the number of time that he failed.
is there an option of how to get that with visualization.
thank you for replying.