Compartir a través de


search operator

Applies to: ✅Microsoft FabricAzure Data ExplorerAzure MonitorMicrosoft Sentinel

Busca un patrón de texto en varias tablas y columnas.

Note

If you know the specific tables and columns you want to search, it's more performant to use the union and where operators. El search operador puede ser lento al buscar en un gran número de tablas y columnas.

Syntax

[T|] search [kind=CaseSensitivity ] [in(TableSources)] SearchPredicate

Learn more about syntax conventions.

Parameters

Name Type Required Description
T string The tabular data source to be searched over, such as a table name, a union operator, or the results of a tabular query. Can't be specified together with TableSources.
CaseSensitivity string Marca que controla el comportamiento de todos los string operadores escalares, como has, con respecto a la distinción entre mayúsculas y minúsculas. Los valores válidos son default, case_insensitive, case_sensitive. Las opciones default y case_insensitive son sinónimos, ya que el comportamiento predeterminado no distingue mayúsculas de minúsculas.
TableSources string Lista separada por comas de nombres de tabla "comodín" para participar en la búsqueda. The list has the same syntax as the list of the union operator. Can't be specified together with tabular data source (T).
SearchPredicate string ✔️ Expresión booleana que se va a evaluar para cada registro de la entrada. Si devuelve true, se genera el registro. Consulte Sintaxis de predicado de búsqueda.

Note

If both tabular data source (T) and TableSources are omitted, the search is carried over all unrestricted tables and views of the database in scope.

Sintaxis de predicado de búsqueda

The SearchPredicate allows you to search for specific terms in all columns of a table. El operador que se aplica a un término de búsqueda depende de la presencia y colocación de un asterisco comodín (*) en el término , como se muestra en la tabla siguiente.

Literal Operator
billg has
*billg hassuffix
billg* hasprefix
*billg* contains
bi*lg matches regex

También puede restringir la búsqueda a una columna específica, buscar una coincidencia exacta en lugar de una coincidencia de términos o buscar por expresión regular. La sintaxis de cada uno de estos casos se muestra en la tabla siguiente.

Syntax Explanation
ColumnName:StringLiteral Esta sintaxis se puede usar para restringir la búsqueda a una columna específica. El comportamiento predeterminado es buscar en todas las columnas.
ColumnName==StringLiteral Esta sintaxis se puede usar para buscar coincidencias exactas de una columna con un valor de cadena. El comportamiento predeterminado es buscar una coincidencia de términos.
Columnmatches regexStringLiteral This syntax indicates regular expression matching, in which StringLiteral is the regex pattern.

Use expresiones booleanas para combinar condiciones y crear búsquedas más complejas. Por ejemplo, "error" and x==123 daría lugar a una búsqueda de registros que tengan el término error en cualquier columna y el valor 123 de la x columna.

Ejemplos de sintaxis de predicado de búsqueda

# Syntax Significado (equivalente where) Comments
1 search "err" where * has "err"
2 search in (T1,T2,A*) "err" union T1,T2,A* | donde * tiene "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 Todas las comparaciones de cadenas distinguen mayúsculas de minúsculas
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)

Remarks

Unlike the find operator, the search operator doesn't support the following syntax:

  1. withsource=: la salida siempre incluye una columna denominada $table de tipo string cuyo valor es el nombre de tabla del que se recuperó cada registro (o algún nombre generado por el sistema si el origen no es una tabla, sino una expresión compuesta).
  2. project=, project-smart: el search operador no admite estas opciones para personalizar las columnas de salida. En su lugar, selecciona automáticamente un conjunto de columnas relevante para la salida, que es equivalente al conjunto de columnas recuperado por la project-smart opción en el find operador .

Examples

The examples in this article use publicly available tables in the help cluster, such as the StormEvents table in the Samples database.

The examples in this article use publicly available tables, such as the Weather table in the Weather analytics sample gallery. Es posible que tenga que modificar el nombre de la tabla en la consulta de ejemplo para que coincida con la tabla del área de trabajo.

En el ejemplo siguiente se muestra cómo ejecutar una búsqueda de términos globales. Search for the term Green in all the tables of the ContosoSales database.

The output finds records with the term Green as a last name or a color in the Customers, Products, and SalesTable tables.

 search "Green"

Output

$table CityName ContinentName CustomerKey Education FirstName Gender LastName
Customers Ballard North America 16549 Partial College Mason M Green
Customers Bellingham North America 2070 High School Adam M Green
Customers Bellingham North America 10658 Bachelors Sara F Green
Customers Beverly Hills North America 806 Graduate Degree Richard M Green
Customers Beverly Hills North America 7674 Graduate Degree James M Green
Customers Burbank North America 5241 Graduate Degree Madeline F Green

En el ejemplo siguiente se muestra cómo ejecutar una búsqueda de términos globales condicionales. Search for records that contain the term Green and one of either terms Deluxe or Proseware in the ContosoSales database.

search "Green" and ("Deluxe" or "Proseware")

Output

$table ProductName Manufacturer ColorName ClassName ProductCategoryName
Products Reloj de Contoso de 8 GB & reproductor de RADIO MP3 X850 verde Contoso, Ltd Green Deluxe Audio
Products Proseware Scan Jet Digital Flat Bed Scanner M300 Green Proseware, Inc. Green Regular Computers
Products Proseware All-In-One Photo Printer M200 Green Proseware, Inc. Green Regular Computers
Products Proseware Ink Jet Wireless All-In-One Impresora M400 Verde Proseware, Inc. Green Regular Computers
Products Proseware Ink Jet Instant PDF Sheet-Fed Escáner M300 Verde Proseware, Inc. Green Regular Computers
Products Proseware Desk Jet All-in-One Printer, Scanner, Copier M350 Green Proseware, Inc. Green Regular Computers
Products Proseware Duplex Scanner M200 Green Proseware, Inc. Green Regular Computers

En el ejemplo siguiente se muestra cómo buscar un término dentro de una tabla específica. Search for the term Green only in the Customers table.

search in (Products) "Green"

Output

$table ProductName Manufacturer ColorName
Products Contoso 4G MP3 Player E400 Green Contoso, Ltd Green
Products Contoso 8GB Super-Slim MP3/Video Player M800 Green Contoso, Ltd Green
Products Contoso 16GB Mp5 Player M1600 Green Contoso, Ltd Green
Products Reloj de Contoso de 8 GB & reproductor de RADIO MP3 X850 verde Contoso, Ltd Green
Products Auriculares estéreo Bluetooth inalámbrico NT M402 Verde Northwind Traders Green
Products Transmisor inalámbrico NT y auriculares Bluetooth M150 Verde Northwind Traders Green

En el ejemplo siguiente se muestra cómo buscar un término que distingue mayúsculas de minúsculas. Search for records that match the case-sensitive term in the ContosoSales database.

search kind=case_sensitive "blue"

Output

$table ProductName Manufacturer ColorName ClassName
Products Contoso 16GB New Generation MP5 Player M1650 blue Contoso, Ltd blue Regular
Products Batería De luz brillante de Contoso E20 azul Contoso, Ltd blue Economy
Products Litware 120mm Blue LED Case Fan E901 blue Litware, Inc. blue Economy
NewSales Litware 120mm Blue LED Case Fan E901 blue Litware, Inc. blue Economy
NewSales Litware 120mm Blue LED Case Fan E901 blue Litware, Inc. blue Economy
NewSales Litware 120mm Blue LED Case Fan E901 blue Litware, Inc. blue Economy
NewSales Litware 120mm Blue LED Case Fan E901 blue Litware, Inc. blue Economy

En el ejemplo siguiente se muestra cómo buscar un término en columnas específicas. Search for the terms Aaron and Hughes, in the "FirstName" and "LastName" columns respectively, in the ContosoSales database.

search FirstName:"Aaron" or LastName:"Hughes"

Output

$table CustomerKey Education FirstName Gender LastName
Customers 18285 High School Riley F Hughes
Customers 802 Graduate Degree Aaron M Sharma
Customers 986 Bachelors Melanie F Hughes
Customers 12669 High School Jessica F Hughes
Customers 13436 Graduate Degree Mariah F Hughes
Customers 10152 Graduate Degree Aaron M Campbell

En el ejemplo siguiente se muestra cómo buscar un término con una marca de tiempo. Search for the term Hughes in the ContosoSales database, if the term appears in a record with a date greater than the given date in 'datetime'.

search "Hughes" and DateKey > datetime('2009-01-01')

Output

$table DateKey SalesAmount_real
SalesTable 2021-12-13T00:00:00Z 446.4715
SalesTable 2021-12-13T00:00:00Z 120.555
SalesTable 2021-12-13T00:00:00Z 48.4405
SalesTable 2021-12-13T00:00:00Z 39.6435
SalesTable 2021-12-13T00:00:00Z 56.9905

Performance Tips

# Tip Prefer Over
1 Preferir usar un único search operador en varios operadores consecutivos search search "billg" and ("steveb" or "satyan") buscar "billg" | buscar "steveb" o "satyan"
2 Preferir filtrar dentro del search operador search "billg" and "steveb" search * | donde * tiene "billg" y * tiene "steveb"