你当前正在访问 Microsoft Azure Global Edition 技术文档网站。 如果需要访问由世纪互联运营的 Microsoft Azure 中国技术文档网站,请访问 https://docs.azure.cn

find 运算符

适用于:✅✅Azure 数据资源管理器Azure Monitor✅ Sentinel

在一组表中查找与谓词匹配的行。

find 运算符的范围也可以是跨数据库或跨群集。

find in (Table1, Table2, Table3) where Fruit=="apple"

find in (database('*').*) where Fruit == "apple"

find in (cluster('cluster_name').database('MyDB*').*) where Fruit == "apple"
find in (Table1, Table2, Table3) where Fruit=="apple"

注意

find 运算符实际上比特定于列的文本筛选效率低。 每当列已知时,建议使用 where 运算符。 当工作区包含大量表和列以及正在扫描的数据量较高且查询的时间范围较高时,find 效果不佳。

语法

  • find [withsource= ColumnName] [in()] where谓词 [project-smart | projectColumnName[:ColumnType , ... ] [,pack_all()]]

  • find 谓词 [project-smart | projectColumnName[:ColumnType , ... ] [,pack_all()]]

详细了解语法约定

参数

客户 类型​​ 必需 描述
ColumnName string 默认情况下,输出包含一个名为 source_ 的列,其值指示哪个源表对每行的贡献。 如果指定,则使用 ColumnName,而不是使用 source_。 通配符匹配后,如果查询引用来自多个数据库(包括默认数据库)的表,则此列的值具有与数据库限定的表名称。 同样,如果引用了多个群集,则 群集数据库 限定存在于值中。
Predicate bool ✔️ 为每个输入表中的每一行计算此布尔表达式。 有关详细信息,请参阅谓词语法详细信息
string 零个或零个以上的逗号分隔的表格引用。 默认情况下,find 在当前数据库中的所有表中查找。 可用工具如下:
1. 表的名称,例如 Events
2. 查询表达式,例如 (Events | where id==42)
3. 使用通配符指定的一组表。 例如,E* 将构成数据库中所有名称以 E 开头的表的并集。
project-smartproject string 如果未指定,则默认使用 project-smart。 有关详细信息,请参阅输出架构详细信息
  • withsource=ColumnName:可选。 默认情况下,输出包含一个名为 source_ 的列,其值指示哪个源表贡献了每一行。 如果指定,则使用 ColumnName,而不是使用 source_

  • 谓词:针对输入表 booleanTable [Table...] 的 ,表达式。对每个输入表中的每一行执行计算。 有关详细信息,请参阅谓词语法详细信息

  • Tables:可选。 零个或零个以上的逗号分隔的表格引用。 默认情况下,查找 搜索所有表:

    • 表的名称,如 Events
    • 查询表达式,如 (Events | where id==42)
    • 使用通配符指定的一组表。 例如,E* 将构成所有名称以 E 开头的表的并集。
  • project-smart | project:如果未指定 project-smart,则默认使用。 有关详细信息,请参阅输出架构详细信息

返回

Predicate 为 的 Table [, Table, ...] 中的行的转换true。 行根据输出架构进行转换。

输出架构

source_ 列

find 运算符输出始终包含具有源表名称的 source_ 列。 可以使用 withsource 参数重命名该列。

结果列

筛选掉不包含谓词计算使用的任何列的源表。

使用 project-smart时,输出中显示的列为:

  • 在谓词中显式显示的列。
  • 所有筛选的表的公共列。

其余列将打包到属性包中,并出现在额外的 pack 列中。 由谓词显式引用的列,并出现在具有多个类型的多个表中,每个此类类型的结果架构中都有一个不同的列。 每个列名都是从原始列名和类型构造的,用下划线分隔。

使用 projectColumnName[:ColumnType , ... ] [,pack_all()] 时:

  • 结果表包括列表中指定的列。 如果源表不包含特定列,则相应行中的值为 null。
  • 使用 ColumnName指定 ColumnType 时,“result”中的此列具有给定类型,并且值会根据需要强制转换为该类型。 在计算 谓词时,强制转换对列类型没有影响。
  • 使用 pack_all() 时,所有列(包括投影列)都会打包到属性包中,并默认显示为“column1”。 在该属性包中,源列名称用作属性名称,列的值用作属性值。

谓词语法

find 运算符支持 * has 术语的替代语法,并且仅使用 术语搜索所有输入列的字词。

有关某些筛选函数的摘要,请参阅 where 运算符

考虑

  • 如果 project 子句引用了出现在多个表中且具有多种类型的列,则在 project 子句中,类型必须遵循此列引用
  • 如果列出现在多个表中,并且有多个类型和 project-smart 正在使用,则 find结果中的每个类型都有对应的列,如 联合
  • 使用 项目智能时,谓词、源表集或表架构中的更改可能会导致输出架构更改。 如果需要常量结果架构,请改用 project
  • find 作用域不能包括函数。 若要在 find 范围中包含函数,请使用 view 关键字定义 let 语句

性能提示

  • 使用,而不是表格表达式。 如果使用表格表达式,则 find 运算符将回退到 union 查询,这可能会导致性能下降。
  • 如果列出现在多个表中并具有多种类型,并且是 project 子句的一部分,则在将表传递给 之前,最好将 ColumnType 添加到 project 子句,而不是修改表。
  • 向谓词添加基于时间的筛选器。 使用日期/时间列值或 ingestion_time()
  • 搜索特定列而不是全文搜索。
  • 最好不要引用出现在多个表中且具有多个类型的列。 如果在解析多个类型的此类列类型时谓词有效,则查询会回退到联合。 例如,请参阅 find 充当联合的情况的示例。

示例

本文中的示例使用 帮助群集中的公开可用表,例如 示例 数据库中的 StormEvents 表。

本文中的示例使用公开可用的表,例如天气分析中的 StormEvents示例数据

跨所有表进行字词查找

以下查询从当前数据库的所有表中查找其中的任意列包含单词 Hernandez 的所有行。 生成的记录根据输出架构进行转换。 输出包括来自 Customers 数据库的 SalesTable 表和 ContosoSales 表的行。

find "Hernandez"

输出

此表显示输出的前三行。

source_ pack_
客户 {“CityName”:“Ballard”,“CompanyName”:“NULL”,“ContinentName”:“North America”,“CustomerKey”:5023,“Education”:“Partial High School”,“FirstName”:“Devin”,“Gender”:“M”,“LastName”:“Hernandez”,“MaritalStatus”:“S”,“职业”:“Clerical”,“RegionCountryName”:“美国”,“StateProvinceName”:“Washington”}
客户 {“CityName”:“Ballard”,“CompanyName”:“NULL”,“ContinentName”:“North America”,“CustomerKey”:7814,“Education”:“Partial College”,“FirstName”:“Kristy”,“Gender”:“F”,“LastName”:“Hernandez”,“MaritalStatus”:“S”,“职业”:“Professional”,“RegionCountryName”:“美国”,“StateProvinceName”:“Washington” }
客户 {“CityName”:“Ballard”,“CompanyName”:“NULL”,“ContinentName”:“North America”,“CustomerKey”:7888,“Education”:“Partial High School”,“FirstName”:“Kari”,“Gender”:“F”,“LastName”:“Hernandez”,“MaritalStatus”:“S”,“职业”:“Clerical”,“RegionCountryName”:“美国”,“StateProvinceName”:“Washington”}
... ...

与名称模式匹配的所有表的术语查找

以下查询从当前数据库中名称以 C 开头的所有表中,查找其中的任意列包含单词 Hernandez 的所有行。 生成的记录根据输出架构进行转换。 现在,输出仅包含 Customers 表中的记录。

find in (C*) where * has "Hernandez"

输出

此表显示输出的前三行。

source_ pack_
ConferenceSessions {“conference”:“Build 2021”,“sessionid”:“CON-PRT103”,“session_title”:“Roundtable: Advanced Kusto query language topics”,“session_type”:“Roundtable”,“owner”:“Avner Aharoni”,“参与者”:“Alexander Sloutsky, Tzvia Gitlin-Troyna”,“URL”:“https://sessions.mybuild.microsoft.com/sessions/details/4d4887e9-f08d-4f88-99ac-41e5feb869e7",”level“:200,”session_location“:”Online“,”starttime“:”2021-05-26T08:30:00.00000000Z“,”duration“:60,”time_and_duration“:”星期三, 5 月 26 日\n上午 8:30 - 格林尼治标准时间上午 9:30“,”kusto_affinity“:”重点“}
ConferenceSessions {“conference”:“Ignite 2018”,“sessionid”:“THR3115”,“session_title”:“Azure Log Analytics: 深入了解 Azure Kusto 查询语言。 “,”session_type“:”Theater“,”owner“:”Jean Francois Berenguer“,”participants“:”“,”URL“:”https://myignite.techcommunity.microsoft.com/sessions/66329",“level”:300,“session_location”:“”,“starttime”:null,“duration”:null,“time_and_duration”:“”,“kusto_affinity”:“Focused”}
ConferenceSessions {“conference”:“Build 2021”,“sessionid”:“CON-PRT103”,“session_title”:“Roundtable: Advanced Kusto query language topics”,“session_type”:“Roundtable”,“owner”:“Avner Aharoni”,“参与者”:“Alexander Sloutsky, Tzvia Gitlin-Troyna”,“URL”:“https://sessions.mybuild.microsoft.com/sessions/details/4d4887e9-f08d-4f88-99ac-41e5feb869e7",”level“:200,”session_location“:”Online“,”starttime“:”2021-05-26T08:30:00.00000000Z“,”duration“:60,”time_and_duration“:”星期三, 5 月 26 日\n上午 8:30 - 格林尼治标准时间上午 9:30“,”kusto_affinity“:”重点“}
... ...

跨群集的术语查找

该查询查找群集中所有数据库中所有表中的所有行,其中任何列都包含单词 Kusto。 此查询是一个跨数据库查询。 生成的记录根据输出架构进行转换。

find in (database('*').*) where * has "Kusto"

输出

此表显示输出的前三行。

source_ pack_
database(“示例”)。ConferenceSessions {“conference”:“Build 2021”,“sessionid”:“CON-PRT103”,“session_title”:“Roundtable: Advanced Kusto query language topics”,“session_type”:“Roundtable”,“owner”:“Avner Aharoni”,“参与者”:“Alexander Sloutsky, Tzvia Gitlin-Troyna”,“URL”:“https://sessions.mybuild.microsoft.com/sessions/details/4d4887e9-f08d-4f88-99ac-41e5feb869e7",”level“:200,”session_location“:”Online“,”starttime“:”2021-05-26T08:30:00.00000000Z“,”duration“:60,”time_and_duration“:”星期三, 5 月 26 日\n上午 8:30 - 格林尼治标准时间上午 9:30“,”kusto_affinity“:”重点“}
database(“示例”)。ConferenceSessions {“conference”:“Ignite 2018”,“sessionid”:“THR3115”,“session_title”:“Azure Log Analytics: 深入了解 Azure Kusto 查询语言。 “,”session_type“:”Theater“,”owner“:”Jean Francois Berenguer“,”participants“:”“,”URL“:”https://myignite.techcommunity.microsoft.com/sessions/66329",“level”:300,“session_location”:“”,“starttime”:null,“duration”:null,“time_and_duration”:“”,“kusto_affinity”:“Focused”}
database(“示例”)。ConferenceSessions {“conference”:“Build 2021”,“sessionid”:“CON-PRT103”,“session_title”:“Roundtable: Advanced Kusto query language topics”,“session_type”:“Roundtable”,“owner”:“Avner Aharoni”,“参与者”:“Alexander Sloutsky, Tzvia Gitlin-Troyna”,“URL”:“https://sessions.mybuild.microsoft.com/sessions/details/4d4887e9-f08d-4f88-99ac-41e5feb869e7",”level“:200,”session_location“:”Online“,”starttime“:”2021-05-26T08:30:00.00000000Z“,”duration“:60,”time_and_duration“:”星期三, 5 月 26 日\n上午 8:30 - 格林尼治标准时间上午 9:30“,”kusto_affinity“:”重点“}
... ...

与群集中名称模式匹配的字词查找

以下查询从所有名称以 K 开头的表中和所有名称以 B 开头的数据库中,查找其中的任意列包含单词 Kusto 的所有行。 生成的记录根据输出架构进行转换。

find in (database("S*").C*) where * has "Kusto"

输出

此表显示输出的前三行。

source_ pack_
ConferenceSessions {“conference”:“Build 2021”,“sessionid”:“CON-PRT103”,“session_title”:“Roundtable: Advanced Kusto query language topics”,“session_type”:“Roundtable”,“owner”:“Avner Aharoni”,“参与者”:“Alexander Sloutsky, Tzvia Gitlin-Troyna”,“URL”:“https://sessions.mybuild.microsoft.com/sessions/details/4d4887e9-f08d-4f88-99ac-41e5feb869e7",”level“:200,”session_location“:”Online“,”starttime“:”2021-05-26T08:30:00.00000000Z“,”duration“:60,”time_and_duration“:”星期三, 5 月 26 日\n上午 8:30 - 格林尼治标准时间上午 9:30“,”kusto_affinity“:”重点“}
ConferenceSessions {“conference”:“Build 2021”,“sessionid”:“CON-PRT103”,“session_title”:“Roundtable: Advanced Kusto query language topics”,“session_type”:“Roundtable”,“owner”:“Avner Aharoni”,“参与者”:“Alexander Sloutsky, Tzvia Gitlin-Troyna”,“URL”:“https://sessions.mybuild.microsoft.com/sessions/details/4d4887e9-f08d-4f88-99ac-41e5feb869e7",”level“:200,”session_location“:”Online“,”starttime“:”2021-05-26T08:30:00.00000000Z“,”duration“:60,”time_and_duration“:”星期三, 5 月 26 日\n上午 8:30 - 格林尼治标准时间上午 9:30“,”kusto_affinity“:”重点“}
ConferenceSessions {“conference”:“Build 2021”,“sessionid”:“CON-PRT103”,“session_title”:“Roundtable: Advanced Kusto query language topics”,“session_type”:“Roundtable”,“owner”:“Avner Aharoni”,“参与者”:“Alexander Sloutsky, Tzvia Gitlin-Troyna”,“URL”:“https://sessions.mybuild.microsoft.com/sessions/details/4d4887e9-f08d-4f88-99ac-41e5feb869e7",”level“:200,”session_location“:”Online“,”starttime“:”2021-05-26T08:30:00.00000000Z“,”duration“:60,”time_and_duration“:”星期三, 5 月 26 日\n上午 8:30 - 格林尼治标准时间上午 9:30“,”kusto_affinity“:”重点“}
... ...

在多个群集中进行字词查找

以下查询从所有名称以 K 开头的表中和所有名称以 B 开头的数据库中,查找其中的任意列包含单词 Kusto 的所有行。 生成的记录根据输出架构进行转换。

find in (cluster("cluster1").database("B*").K*, cluster("cluster2").database("C*".*))
where * has "Kusto"

跨所有表进行字词查找

以下查询从所有表中查找其中的任意列包含单词 Kusto 的所有行。 生成的记录根据输出架构进行转换。

find "Kusto"

find 输出结果的示例

下面的示例演示如何针对两个表使用 find:EventsTable1 和 EventsTable2 。 假设我们有这两个表的以下内容:

EventsTable1

Session_Id 级别 EventText 版本
acbd207d-51aa-4df7-bfa7-be70eb68f04e 信息 Some Text1 v1.0.0
acbd207d-51aa-4df7-bfa7-be70eb68f04e 错误 Some Text2 v1.0.0
28b8e46e-3c31-43cf-83cb-48921c3986fc 错误 Some Text3 v1.0.1
8f057b11-3281-45c3-a856-05ebb18a3c59 信息 Some Text4 v1.1.0

EventsTable2

Session_Id 级别 EventText EventName
f7d5f95f-f580-4ea6-830b-5776c8d64fdd 信息 Some Other Text1 Event1
acbd207d-51aa-4df7-bfa7-be70eb68f04e 信息 Some Other Text2 Event2
acbd207d-51aa-4df7-bfa7-be70eb68f04e 错误 Some Other Text3 Event3
15eaeab5-8576-4b58-8fc6-478f75d8fee4 错误 Some Other Text4 Event4

在常见列、项目通用和不常见列中搜索,并打包其余列

查询根据给定 Session_Id错误 级别搜索 EventsTable1EventsTable2 中的特定记录。 然后,它会投影三个特定列:EventTextVersionEventName,并将所有其他剩余列打包到动态对象中。

find in (EventsTable1, EventsTable2) 
     where Session_Id == 'acbd207d-51aa-4df7-bfa7-be70eb68f04e' and Level == 'Error' 
     project EventText, Version, EventName, pack_all()

输出

source_ EventText 版本 EventName pack_
EventsTable1 Some Text2 v1.0.0 {"Session_Id":"acbd207d-51aa-4df7-bfa7-be70eb68f04e", "Level":"Error"}
EventsTable2 Some Other Text3 Event3 {"Session_Id":"acbd207d-51aa-4df7-bfa7-be70eb68f04e", "Level":"Error"}

搜索公共列和非公共列

查询将搜索 版本 为“v1.0.0”或 EventName 为“Event1”的记录,然后它投影(选择)四个特定列:Session_IdEventText版本,以及从筛选结果 EventName

find Version == 'v1.0.0' or EventName == 'Event1' project Session_Id, EventText, Version, EventName

输出

source_ Session_Id EventText 版本 EventName
EventsTable1 acbd207d-51aa-4df7-bfa7-be70eb68f04e Some Text1 v1.0.0
EventsTable1 acbd207d-51aa-4df7-bfa7-be70eb68f04e Some Text2 v1.0.0
EventsTable2 f7d5f95f-f580-4ea6-830b-5776c8d64fdd Some Other Text1 Event1

注意

在实践中,使用谓词 Version == 'v1.0.0' 筛选 eventsTable1 EventsTable2 行使用 EventName == 'Event1' 谓词进行筛选。

使用缩写表示法在当前数据库的所有表中进行搜索

此查询在数据库中搜索与“acbd207d-51aa-4df7-bfa7-be70eb68f04e”匹配 Session_Id 的任何记录。 它从包含此特定 Session_Id的所有表和列中检索记录。

find Session_Id == 'acbd207d-51aa-4df7-bfa7-be70eb68f04e'

输出

source_ Session_Id 级别 EventText pack_
EventsTable1 acbd207d-51aa-4df7-bfa7-be70eb68f04e 信息 Some Text1 {"Version":"v1.0.0"}
EventsTable1 acbd207d-51aa-4df7-bfa7-be70eb68f04e 错误 Some Text2 {"Version":"v1.0.0"}
EventsTable2 acbd207d-51aa-4df7-bfa7-be70eb68f04e 信息 Some Other Text2 {"EventName":"Event2"}
EventsTable2 acbd207d-51aa-4df7-bfa7-be70eb68f04e 错误 Some Other Text3 {"EventName":"Event3"}

以属性包的形式返回每一行的结果

此查询在数据库中搜索具有指定 Session_Id 的记录,并将这些记录的所有列作为单个动态对象返回。

find Session_Id == 'acbd207d-51aa-4df7-bfa7-be70eb68f04e' project pack_all()

输出

source_ pack_
EventsTable1 {"Session_Id":"acbd207d-51aa-4df7-bfa7-be70eb68f04e", "Level":"Information", "EventText":"Some Text1", "Version":"v1.0.0"}
EventsTable1 {"Session_Id":"acbd207d-51aa-4df7-bfa7-be70eb68f04e", "Level":"Error", "EventText":"Some Text2", "Version":"v1.0.0"}
EventsTable2 {"Session_Id":"acbd207d-51aa-4df7-bfa7-be70eb68f04e", "Level":"Information", "EventText":"Some Other Text2", "EventName":"Event2"}
EventsTable2 {"Session_Id":"acbd207d-51aa-4df7-bfa7-be70eb68f04e", "Level":"Error", "EventText":"Some Other Text3", "EventName":"Event3"}

find 充当 union 的情况示例

Kusto 中的 find 运算符有时可以像 union 运算符一样,这主要是当它用于跨多个表进行搜索时。

将非表格表达式用作查找操作数

查询首先创建一个视图,该视图筛选 EventsTable1 以仅包含错误级别记录。 然后,它会在此筛选视图和 EventsTable2 表中搜索具有特定 Session_Id的记录。

let PartialEventsTable1 = view() { EventsTable1 | where Level == 'Error' };
find in (PartialEventsTable1, EventsTable2) 
     where Session_Id == 'acbd207d-51aa-4df7-bfa7-be70eb68f04e'

引用出现在多个表中并具有多个类型的列

对于此示例,通过运行创建两个表:

.create tables 
  Table1 (Level:string, Timestamp:datetime, ProcessId:string),
  Table2 (Level:string, Timestamp:datetime, ProcessId:int64)
  • 以下查询将作为 union执行。
find in (Table1, Table2) where ProcessId == 1001

输出结果架构 (Level:string、Timestamp、ProcessId_string、ProcessId_int)

  • 以下查询将作为 union执行,但会生成不同的结果架构。
find in (Table1, Table2) where ProcessId == 1001 project Level, Timestamp, ProcessId:string 

输出结果架构 (Level:string、Timestamp、ProcessId_string)