search 運算子
在多個數據表和數據行中搜尋文字模式。
Syntax
[T|
] search
[kind=
CaseSensitivity ] [in
(
TableSources)
] SearchPredicate
深入瞭解 語法慣例。
參數
名稱 | 類型 | 必要 | Description |
---|---|---|---|
T | string |
要搜尋的表格式數據來源,例如數據表名稱、 等位運算符或表格式查詢的結果。 無法與 TableSources 一起出現。 | |
CaseSensitivity | string |
旗標,控制所有 string 純量運算符的行為,例如 has ,對於區分大小寫。 有效值為 default 、 case_insensitive 、 case_sensitive 。 選項 default 和 case_insensitive 是同義的,因為預設行為不區分大小寫。 |
|
TableSources | string |
要參與搜尋的「通配符」數據表名稱逗號分隔清單。 清單具有與 union 運算子清單相同的語法。 無法與 TabularSource 一起出現。 | |
SearchPredicate | string |
✔️ | 要針對輸入中的每個記錄評估的布爾表達式。 如果傳回 true ,則會輸出記錄。 請參閱 搜尋述詞語法。 |
搜尋述詞語法
SearchPredicate 可讓您在資料表的所有數據行中搜尋特定字詞。 將套用至搜尋字詞的運算符取決於通配符星號 () *
在字詞中的存在和位置,如下表所示。
常值 | 運算子 |
---|---|
billg |
has |
*billg |
hassuffix |
billg* |
hasprefix |
*billg* |
contains |
bi*lg |
matches regex |
您也可以將搜尋限制為特定數據行、尋找完全相符專案,而不是字詞比對,或依正則表達式搜尋。 下表顯示上述每個案例的語法。
Syntax | 說明 |
---|---|
ColumnName: StringLiteral |
此語法可用來將搜尋限制為特定數據行。 默認行為是搜尋所有數據行。 |
ColumnName== StringLiteral |
此語法可用來針對字串值搜尋數據行的完全相符專案。 默認行為是尋找字詞比對。 |
列matches regex StringLiteral |
此語法表示正則表達式比對,其中 StringLiteral 是 regex 模式。 |
使用布爾表達式來結合條件並建立更複雜的搜尋。 例如,"error" and x==123
會導致搜尋任何數據行中有字詞error
的記錄,以及數據行中的x
值123
。
注意
如果省略 TabularSource 和 TableSources ,搜尋就會包含在範圍中資料庫的所有不受限制的數據表和檢視上。
搜尋述詞語法範例
# | 語法 | 意義 (相當於 where ) |
註解 |
---|---|---|---|
1 | search "err" |
where * has "err" |
|
2 | search in (T1,T2,A*) "err" |
union T1,T2,A* | where * has "err" |
|
3 | search col:"err" |
where col has "err" |
|
4 | search col=="err" |
where col=="err" |
|
5 | search "err*" |
where * hasprefix "err" |
|
6 | search "*err" |
where * hassuffix "err" |
|
7 | search "*err*" |
where * contains "err" |
|
8 | search "Lab*PC" |
where * matches regex @"\bLab.*PC\b" |
|
9 | search * |
where 0==0 |
|
10 | search col matches regex "..." |
where col matches regex "..." |
|
11 | search kind=case_sensitive |
所有字串比較均區分大小寫 | |
12 | search "abc" and ("def" or "hij") |
where * has "abc" and (* has "def" or * has hij") |
|
13 | search "err" or (A>a and A<b) |
where * has "err" or (A>a and A<b) |
備註
不同於 find 運算子,search
運算子不支援下列各項:
withsource=
:如果來源不是數據表,但複合表達式) ,則輸出一律會包含稱為$table
類型的string
數據行,其值為每個記錄 (擷取的數據表名稱或某些系統產生的名稱。project=
、project-smart
:輸出結構描述相當於project-smart
輸出結構描述。
範例
全域字詞搜尋
搜尋範圍中資料庫之所有不受限制數據表和檢視的字詞。
search "Green"
輸出包含、 Products
和 SalesTable
資料表中的Customers
記錄。 記錄 Customers
會顯示姓氏為 「Green」 的所有客戶,而 Products
和 SalesTable
記錄則會顯示具有一些「綠色」提及的產品。
條件式全域字詞搜尋
搜尋符合範圍中資料庫所有不受限制數據表和檢視之兩個詞彙的記錄。
search "Green" and ("Deluxe" or "Proseware")
搜尋特定數據表
只在數據表中 Customers
搜尋。
search in (Products) "Green"
區分大小寫的搜尋
搜尋在範圍內所有不受限制之數據表和檢視表上符合區分大小寫詞彙的記錄。
search kind=case_sensitive "blue"
搜尋特定數據行
在範圍中所有不受限制的數據表和檢視中,搜尋 「FirstName」 和 「LastName」 資料行中的字詞。
search FirstName:"Aaron" or LastName:"Hughes"
依時間戳限制搜尋
如果字詞出現在日期大於指定日期的記錄中,則搜尋範圍中資料庫所有不受限制數據表和檢視的字詞。
search "Hughes" and DateKey > datetime('2009-01-01')
效能祕訣
# | 提示 | 偏好 | 超過 |
---|---|---|---|
1 | 最好有數個連續的 search 運算子使用單一 search 運算子 |
search "billg" and ("steveb" or "satyan") |
search "billg" | search "steveb" or "satyan" |
2 | 偏好在 search 運算子內篩選 |
search "billg" and "steveb" |
search * | where * has "billg" and * has "steveb" |
意見反應
https://aka.ms/ContentUserFeedback。
即將登場:在 2024 年,我們將逐步淘汰 GitHub 問題作為內容的意見反應機制,並將它取代為新的意見反應系統。 如需詳細資訊,請參閱:提交並檢視相關的意見反應