# Need helpppppp

**URL:** https://discuss.elastic.co/t/need-helpppppp/172161
**Category:** Kibana
**Created:** [March 13, 2019, 1:50pm UTC](https://discuss.elastic.co/t/need-helpppppp/172161 "2019-03-13T13:50:22Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![souheil](https://avatars.discourse-cdn.com/v4/letter/s/278dde/32.png) [@souheil](https://discuss.elastic.co/u/souheil)
#### Post date: [March 13, 2019, 1:50pm UTC](https://discuss.elastic.co/t/need-helpppppp/172161/1 "2019-03-13T13:50:22Z")

</div>

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](https://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

---

<div class="post-metadata">

### Author: ![Marius\_Dragomir](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/marius_dragomir/32/42087_2.png) [@Marius\_Dragomir](https://discuss.elastic.co/u/Marius_Dragomir)
#### Post date: [March 15, 2019, 9:23am UTC](https://discuss.elastic.co/t/need-helpppppp/172161/2 "2019-03-15T09:23:13Z")

</div>

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.

---

<div class="post-metadata">

### Author: ![souheil](https://avatars.discourse-cdn.com/v4/letter/s/278dde/32.png) [@souheil](https://discuss.elastic.co/u/souheil)
#### Post date: [March 18, 2019, 10:23am UTC](https://discuss.elastic.co/t/need-helpppppp/172161/3 "2019-03-18T10:23:45Z")

</div>

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.

---

<div class="post-metadata">

### Author: ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)
#### Post date: [April 15, 2019, 10:23am UTC](https://discuss.elastic.co/t/need-helpppppp/172161/4 "2019-04-15T10:23:46Z")

</div>

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