I have a first KQL query that returns a list of domain names, and then I want to use these to filter another KQL query. I just can’t figure out the syntax to do it. Is there a way to use the contains() operator with a for loop/iteration in KQL?
KQL – Query 1
let hostnames = () {
AllDomains
| where hostname !contains "default.com" and hostname != ""
| distinct hostname
}
KQL – Query 2
let start_date = ago(10m);
let end_date = now();
LogEvents
| where env_time between (start_date .. end_date)
| where headers contains "X-Forwarded-For"
| where queryString contains (hostnames()) //This is what is needed to filter on all the domains from first query.
| project queryString
2
Answers
It would be better if you’ll provide a sample of how your data looks and what you are trying to accomplish, but I think that instead of
contains
you’d want to usehas_any
this could work: