Available:setTimeInterval() v1.171.0
The setTimeInterval()
function is
available from v1.171.0
setTimeInterval()
can be used to set the
query's time interval and related time settings from within the
query string. When used, the query time specified in the query
string will override the settings from the UI or query API.
Parameter | Type | Required | Default Value | Description |
---|---|---|---|---|
end | string,time point | optional[a] | now | End time of query. When specified, it overrides the end time from the query API. |
start [b] | string,time point | required | Start time of query. When specified, it overrides the start time from the query API. | |
timezone | string,time zone name | optional[a] | Time zone name. When specified, overrides the timezone set from the query API. For a list of timezone names, see the table “Supported Timezones”. | |
[a] Optional parameters use their default value unless explicitly set. |
Using setTimeInterval()
offers several
advantages:
Query users can specify time ranges directly in query strings. The feature enables copying and sharing query strings with other users, who can recreate the search in different views and/or clusters (with different URLs).
Dashboard creators can specify time ranges in query strings. The feature allows setting the static time range for the widgets.
This is a metadata query function that does not process events. It is only used for setting the time interval and related metadata from within the query instead of through the Query Jobs API or the UI.
Using setTimeInterval()
affects both the
API and the UI, as follows.
The
start
andend
parameters of the function override the Query Jobs APIend
andstart
fields, meaning that a query like this:logscalegroupBy([status_code, ip]
with
start=7d
andend=1d
set inQueryInputJob
, is equivalent to query:logscalesetTimeInterval(start=7d, end=1d) | groupBy([status_code, ip]
When the Time field selection is set to in the UI, then the query will be submitted to the QueryInputJob with input useIngestTime equal to
true
. In this scenario, thestart
andend
parameters ofsetTimeInterval()
will override the ingestStart and ingestEnd API fields.When the Time field selection is set to in the UI, then the query will be submitted to the QueryInputJob with input useIngestTime equal to
false
. In this scenario, thestart
andend
parameters ofsetTimeInterval()
will override the start and end API fields.
Using setTimeInterval()
also overrides the
time controls in the UI. See
Change Time Interval and
Shared Time Selector for more
information.
Validation Rules/Known Limitations
The setTimeInterval()
function requires
specific validation rules for correct usage.
Must appear in the preamble of the query — that is, before any other functions, filters, free-text searches, etc.
Must appear before any
defineTable()
definitions.Must appear at most once in a query.
Cannot appear inside
join()
/defineTable()
subqueries. To set a different time range for the ad-hoc table/join subquery, use thestart
andend
parameters that are supported in these functions.Same restrictions as the API time interval apply, that is:
In a live query
start
must be relative, andend
must benow
If the user has search limitations (for example, trial users can only search 7 days back), these limitations still apply
setTimeInterval()
is only supported in ad-hoc searches and on dashboards. In particular,setTimeInterval()
is not supported in:Triggers (aggregate alerts, filter alerts, legacy alerts, scheduled searches)
Filter prefix of a query such as repository filters, user filters, group filters (like any other query functions, which are equally not supported)
setTimeInterval()
Examples
Click
next to an example below to get the full details.Set Time Interval From Within Query
Set the time interval and related metadata from within the query instead of through the QueryJobs API or UI
Set Time Interval From Within Query with defineTable()
Set the time interval and related metadata from within the query instead of through the test QueryJobs API or UI using the defineTable()
function