Querying data synchronously in IBM Cloud Logs
In IBM Cloud Logs, you can run a synchronously query using DataPrime or Lucene syntax to query the data.
Running queries through the UI in IBM Cloud Logs
In IBM Cloud Logs, you can query data through the Logs Explorer page by using any of the following options:
In the Logs Explorer > Logs page, you can choose any of the following options to query data:
-
You can monitor Priority insights data through the Priority Insights option.
-
You can monitor data through the All Logs option that is available in the COS data bucket and ingested through any data pipeline.
Running synchronous queries through the CLI in IBM Cloud Logs
You can query logs synchronously by runing the ibmcloud logs query command.
ibmcloud logs query ibmcloud cloud-logs query [--query "DATAPRIME_OR_LUCENE_QUERY"] \
[--metadata '{ --start-date START-DATE
--end-date END-DATE
--default-source DEFAULT-SOURCE
--tier TIER
--syntax SYNTAX
--limit LIMIT
--strict-fields-validation STRICT-FIELDS-VALIDATION
}'
Where
--query(string)-
Defines the query to be run.
The maximum length is 4096 characters.
--metadata(string)-
Metadata for the query execution. Use this configuration to provide the query execution parameters.
--start-date(string)-
Beginning of the time range for the query.
This must be in UTC ISO 8601 format, for example:
2025-07-15T08:45:00Z.The default is 15 minutes before the
--end-datevalue.If
--end-dateis not specified, the default value is 15 minutes before the current time. --end-date(string)-
End of the time range for the query.
This must be in UTC ISO 8601 format, for example:
2025-07-15T08:45:00Z.The default is 15 minutes after the
--start-datevalue.If
--start-dateis not defined the--end-dateis the current-time and the--start-dateis 15 minutes prior to current time. --limit(int)-
Limit the number of records returned.
If not specified, the default value is 2000.
The maximum number of records returned when searching Priority insights is 12000. Otherwise the maximum number of records returned is: 50000.
--default-source(string)-
Default value for the source to use when the source is omitted in a query.
The maximum length is 4096 characters.
--syntax(string)-
The syntax in which the query is written.
Valid values are:
unspecified,lucene,dataprime. --since(duration)-
Duration to look back from the current time when querying data.
Using this flag overrides the
metadata-start-dateandmetadata-end-date.For example,
1hretrieves data from the past hour.The default value is set to
1h0m0s. --tier(string)-
Tier on which the query runs.
Valid values are:
archive, andfrequent_search(Priority insights). --strict-fields-validation(boolean)-
Controls the fields that can be used in queries.
When is set to false, you cannot use fields that are not detected in the ingested data.
The default value is set to
false. --output(string)-
The output format in which the results are returned. Valid values are
logs-raw,logs-prettifyandjson.
For example, you can run the following samples:
ibmcloud logs query --query "Push and Query test" --metadata '{"start_date": "2025-06-16T12:00:00Z", "end_date": "2025-06-17T13:41:30Z","syntax": "lucene"}' --output logs-raw
ibmcloud logs query --query "source logs | filter \$d.text == 'Push and Query test'" --syntax dataprime --start-date 2025-08-03T12:00:00Z --end-date 2025-08-04T13:41:30Z
ibmcloud logs query --query 'severity:ERROR AND applicationName:permission-service AND NOT message:"connection reset"' --syntax lucene --since 1h
Running synchronous queries through the API in IBM Cloud Logs
You can query logs synchronously by running the API method ${URL}/v1/query.
API endpoint for synchronous queries in IBM Cloud Logs
The following table outlines the endpoint details in background queries in IBM Cloud Logs:
| Detail | Value |
|---|---|
URL |
<INSTANCE_ID>.api.<REGION>.logs.cloud.ibm.com/logs/v1/background_query |
Header Content-Type |
application/json |
Header Authorization |
Bearer $IAM_TOKEN |
Header Accept |
application/json |
Where
INSTANCE_ID: GUID of the IBM Cloud Logs instance where you want to run the background query.REGION: Region where the IBM Cloud Logs instance is located.IAM_TOKEN: IAM bearer token used to request authorization to run a background query.
Retrieving an access token when using the API in synchronous queries in IBM Cloud Logs
You can retrieve your access token programmatically by first creating a service ID API key for your application, and then exchanging your API key for an IBM Cloud IAM token. For more information, see Retrieving an access token with the API.
Running a synchronous query in IBM Cloud Logs
In IBM Cloud Logs, the format of the API method to run a synchronous query is the following:
curl -X POST --location --header "Authorization: Bearer ${iam_token}" --header "Accept: text/event-stream" --header "Content-Type: application/json" --data '{
"metadata": {
"end_date": "END_DATE",
"limit": LIMIT,
"start_date": "START_DATE",
"strict_fields_validation": false,
"syntax": "QUERY_SYNTAX",
"tier": "TIER"
},
"query": "QUERY"
}' "${base_url}/v1/query"
Where
query(string)-
Defines the query to be run.
The maximum length is 4096 characters.
metadata(string)-
Metadata for the query execution. Use this configuration to provide the query execution parameters.
start-date(string)-
Beginning of the time range for the query.
This must be in UTC ISO 8601 format, for example:
2025-07-15T08:45:00Z.The default is 15 minutes before the
--end-datevalue.If
--end-dateis not specified, the default value is 15 minutes before the current time. end-date(string)-
End of the time range for the query.
This must be in UTC ISO 8601 format, for example:
2025-07-15T08:45:00Z.The default is 15 minutes after the
--start-datevalue.If
--start-dateis not defined the--end-dateis the current-time and the--start-dateis 15 minutes prior to current time. limit(int)-
Limit the number of records returned.
If not specified, the default value is 2000.
The maximum number of records returned when searching Priority insights is 12000. Otherwise the maximum number of records returned is: 50000.
syntax(string)-
The syntax in which the query is written.
Valid values are:
unspecified,lucene,dataprime. tier(string)-
Tier on which the query runs.
Valid values are:
archive, andfrequent_search(Priority insights). strict-fields-validation(boolean)-
Controls the fields that can be used in queries.
When is set to false, you cannot use fields that are not detected in the ingested data.
The default value is set to
false.
For more information, see Run a query to search the logs.