To get all SearchEvents you will need to make a call to XConnect.
Something like this should do the trick:
using (XConnectClient xConnectClient = Sitecore.XConnect.Client.Configuration.SitecoreXConnectClientConfiguration.GetClient())
{
var searchs = new List<SearchEvent>();
Guid SearchDefinitionID = new Guid("0c179613-2073-41ab-992e-027d03d523bf");
var interactions = await xConnectClient.Interactions.Where(interaction => interaction.Events.Any(ev => ev.DefinitionId == SearchDefinitionID)).ToList();
foreach (var interaction in interactions)
{
foreach (SearchEvent ev in interaction.Events.Where(ev => ev.DefinitionId == SearchDefinitionID).ToList())
{
searchs.Add(ev);
}
}
}
If you are going to be doing regular data extraction and processing from XConnect. I believe it is recommended to use the Sitecore Cortex engine and its projection framework:
https://doc.sitecore.com/xp/en/developers/102/sitecore-experience-platform/projection-framework.html
You could use this to project, group and count data as required. This uses distributed workers, so can be alot faster and more efficient.
I found this to be a great resource if you are interested in the above:
https://github.com/adeneys/cortex-processing-demo