Need helpppppp

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"){
} 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")
def temp = 0;
for (def inc: failed) {
temp += inc;
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

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.

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.

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.