I am trying to display in canvas the users that have more than 10 authentication failed, so I am using this SQL query:
SELECT COUNT(*) as result_count
FROM (
SELECT user.name, COUNT(*) as result
FROM "winlogbeat-*"
WHERE event.category = 'authentication'
AND event.action = 'logon-failed'
GROUP BY user.name
HAVING result > 10
)
Thanks for your answer @AClerk,
So I meant that as I have used SELECT COUNT(*) as result_count in the beginning of the query, I want to calculate the number of the rows which is 3, and not display the rows
SELECT COUNT(distinct user.name) as result_count
FROM (
SELECT user.name, COUNT(*) as result
FROM "winlogbeat-*"
WHERE event.category = 'authentication'
AND event.action = 'logon-failed'
GROUP BY user.name
HAVING result > 10
)
@Abdelhalim,
Why the outer select? If you want the total count of those users, not grouping by user.name should give you what you need, right?
the expected result is: 3
Could it be that event contains arrays that contain both 'authentication' and 'logon-failed', but not for the same array element? That would result in a higher count than you expect, since the query effectively behaves like an OR instead of an AND.
For me I want to count the users which have more than 10 failed authentications, so if I just use group by, it will just give me the number of failed authentication per user. (If I remember well the courses of SQL, as I didn't use SQL since a long time )
I tried this one too :
SELECT user.name, COUNT(*) as result
FROM "winlogbeat-*"
WHERE event.action = 'logon-failed'
GROUP BY user.name
HAVING result > 10
SELECT COUNT(user.name) FROM (
SELECT user.name, COUNT(*) as result
FROM "winlogbeat-*"
WHERE event.action = 'logon-failed'
GROUP BY user.name
HAVING result > 10
)
Ah, I see, I didn't read through initially, sorry.
You're after the count of users that each have more than 10 failed authentications, not the list of those users. That would require a count aggregation over the grouping aggregation, indeed.
Subselects have limited support in ES/SQL currently and as you could see in the limitations, the outer count is "flattened" and that's why you get again a list of counts and not the cardinality of the list.
Hi @Abdelhalim
The key is to select Count or Unique from 'Display' tab. Which will ensure that it counts the number of rows in the result set. If you are familiar with canvas expression language, you can use math function within the element body too.
Apache, Apache Lucene, Apache Hadoop, Hadoop, HDFS and the yellow elephant
logo are trademarks of the
Apache Software Foundation
in the United States and/or other countries.