Kusto Query Language (KQL) is a powerful, highly efficient query language for Azure Data Explorer, Azure Monitor Logs, Azure Sentinel, and Azure Synapse Analytics. It's designed for exploring data and discovering patterns, identifying anomalies, and troubleshooting issues.
KQL queries are read-only queries that describe the data to retrieve. The query is composed of a sequence of query operators, where each operator takes a table (or the output of the previous operator) as input and produces a table as output. This makes it easy to construct complex queries by composing simple operators.
take
: Returns a specified number of rows from the table. Useful for getting a quick sample of your data.where
: Filters rows based on a specified condition.project
: Selects columns and renames them, or calculates new columns.summarize
: Aggregates rows based on grouping expressions, producing summary rows. Often used with aggregation functions like count()
, sum()
, avg()
, dcount()
.sort by
: Sorts the rows by one or more columns.extend
: Adds computed columns to the result.join
: Combines rows from two tables based on matching values in one or more columns.A typical KQL query follows this structure:
TableName
| operator1 arguments
| operator2 arguments
| ...
Let's say you have a table named Logs
with columns like Timestamp
, Level
, Message
, and Source
. To find the 10 most recent error messages:
Logs
| where Level == "Error"
| sort by Timestamp desc
| take 10
| project Timestamp, Message, Source
Built-in functions for time series analysis, including time bucketing and trend detection.
Supports complex data types like dynamic objects, arrays, and geographical data.
Optimized for high-volume, high-velocity data, enabling fast querying over terabytes of data.
Integrates with other Azure services and supports user-defined functions (UDFs).
Functions like mv-avg
and diff
for basic anomaly detection and forecasting.
You can write and execute KQL queries directly within the Azure Synapse Studio for your Data Explorer pools. Explore your data, build dashboards, and create alerts.
count()
: Counts the number of rows.dcount()
: Counts the distinct number of values.sum()
: Calculates the sum of values.avg()
: Calculates the average of values.min()
, max()
: Finds the minimum or maximum value.stdev()
: Calculates the standard deviation.percentiles()
: Calculates specified percentiles.render
operator: Visualize query results directly in charts (e.g., | render timechart
).parse
operator: Extract data from unstructured or semi-structured text.join kinds
: Various join types like innerunique
, leftouter
, inner
.union
operator: Combines the results of multiple queries.For more in-depth information, refer to the official KQL documentation.