简体   繁体   English

如何在第二个查询中使用第一个 KQL 查询的结果来过滤结果?

[英]How to use result of first KQL query in the second query to filter results?

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.我有一个返回域名列表的第一个 KQL 查询,然后我想使用这些查询来过滤另一个 KQL 查询。 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 中将 contains() 运算符与 for 循环/迭代一起使用?

KQL - Query 1 KQL - 查询 1

    let hostnames = () {
    AllDomains 
    | where hostname !contains "default.com" and hostname != ""
    | distinct hostname
   }

KQL - Query 2 KQL - 查询 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 

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 use has_any如果您能提供一个样本,说明您的数据看起来如何以及您想要完成什么,那会更好,但我认为您想要使用has_any而不是contains

this could work:这可以工作:

let hostnames =
    AllDomains 
    | where isnotempty(hostname) and hostname !has "default.com"
    | distinct hostname
;
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 has_any (hostnames)
| project queryString 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM