OpenSearch PPL language
This section contains a basic introduction to querying CloudWatch Logs using OpenSearch PPL. With PPL, you can retrieve, query, and analyze data using piped-together commands, making it easier to understand and compose complex queries. Its syntax is based on Unix pipes, and enables chaining of commands to transform and process data. With PPL, you can filter and aggregate data, and use a rich set of math, string, date, conditional, and other functions for analysis.
You can use OpenSearch PPL only for queries of log groups in the Standard Log Class. When you select which log groups to query, you can select a single log group, a set of log groups that share a prefix, or select all log groups
Note
For information about all OpenSearch PPL query commands supported in CloudWatch Logs and detailed information about syntax and restrictions, see Supported PPL commands in the OpenSearch Service Developer Guide.
Command or function | Example query | Description |
---|---|---|
fields |
|
Displays a set of fields which needs projection. |
join |
|
Joins two datasets together. |
where |
|
Filters the data based on the conditions that you specify. |
stats |
|
Performs aggregations and calculations |
parse |
|
Extracts a regular expression (regex) pattern from a string and displays the extracted pattern. The extracted pattern can be further used to create new fields or filter data. |
sort |
|
Sort the displayed results by a field name. Use sort -FieldName to sort in descending order. |
eval |
|
Modifies or processes the value of a field and stores it in a different field. This is useful to mathematically modify a column, apply string functions to a column, or apply date functions to a column. |
rename |
|
Renames one or more fields in the search result. |
head |
|
Limits the displayed query results to the first N rows. |
top |
|
Finds the most frequent values for a field. |
dedup |
|
Removes duplicate entries based on the fields that you specify. |
rare |
|
Finds the least frequent values of all fields in the field list. |
subquery |
|
Performs complex, nested queries within your PPL statements. |
trendline |
|
Calculates the moving averages of fields. |
eventStats |
|
Enriches your event data with calculated summary statistics. It analyzes specified fields within your events, computes various statistical measures, and then appends these results to each original event as new fields. |
expand |
|
Breaks down a field containing multiple values into separate rows, creating a new row for each value in the specified field. |
fillnull |
|
Fills null fields with the value that you provide. It can be used in one or more fields. |
flatten |
|
Flattens a field. The field must be of this type:
|
cidrmatch |
|
Checks if the specified IP address is within the given CIDR range. |
fieldsummary |
|
Calculates basic statistics for each field (count, distinct count, min, max, avg, stddev, and mean). |
grok |
|
Parses a text field with a grok pattern and appends the results to the search result. |
String functions |
|
Built-in functions in PPL that can manipulate and transform string and text data within PPL queries. For example, converting case, combining strings, extracting parts, and cleaning text. |
Date-Time functions |
|
Built-in functions for handling and transforming date and timestamp data in PPL queries. For example, date_add, date_format, datediff, date-sub, timestampadd, timestampdiff, current_timezone, utc_timestamp, and current_date. |
Condition functions |
|
Built-in functions that check for specific field conditions, and evaluate expressions conditionally. For example, if field1 is null, return field2. |
Math functions |
|
Built-in functions for performing mathematical calculations and transformations in PPL queries. For example, abs (absolute value), round (rounds numbers), sqrt (square root), pow (power calculation), and ceil (rounds up to nearest integer). |
CryptoGraphic functions |
|
To calculate the hash of given field |
JSON functions |
|
Built-in functions for handling JSON including arrays, extracting, and validation. For example, json_object, json_array, to_json_string, json_array_length, json_extract, json_keys, and json_valid. |