Executes a subquery that generates an in-memory, ad-hoc table based on its results. The ad-hoc table can be joined with the results of the primary query using the match() function. For more information on using Ad-hoc tables, see Using Ad-hoc Tables.

defineTable() is the recommended alternative to the join() function, allowing for easier query writing of complex joins. For more explanations on the benefits of using ad-hoc tables with defineTable() instead of join(), see Ad-hoc Tables vs. join().

Combined with match() and readFile() query functions, defineTable() can be used to create several types of join-like queries — see defineTable() Examples.

ParameterTypeRequiredDefault ValueDescription
endstringoptional[a] same as primary query End of time interval of subquery: milliseconds since UNIX epoch or a timestamp relative to the primary query's end time using Relative Time Syntax. For example: if start=7d and the main query's end time is 2024-03-258T14:00:00, then the defineTable() subquery will start at 2024-03-18T14:00:00.
includearray of stringsrequired   Fields to include as columns in the temporary table. If set to * all fields will be included.
namestringrequired   Name of the ad-hoc table that is generated. Used to reference the table in other functions within the primary query.
query[b]functionrequired   Subquery used to generate the ad-hoc table.
startstringoptional[a] same as primary query Start of time interval of subquery: milliseconds since UNIX epoch or a timestamp relative to the primary query's end time using Relative Time Syntax. For example: if start=7d and the main query's end time is 2024-03-25T14:00:00, then the defineTable() subquery will start at 2024-03-18T14:00:00.
viewstringoptional[a] same as primary query View in which to perform the subquery.

[a] Optional parameters use their default value unless explicitly set.

[b] The parameter name query can be omitted.

Hide omitted argument names for this function

Show omitted argument names for this function

The function's signature combined with match():

logscale
defineTable(query={a=hello}, name="tablename", include=[col1,col2,col3])
| match(table="tablename",field=fieldname, column=col1)

For example, to match email data within the same view:

email=bob@example.com firstname=bob lastname=thomas
loginemail=bob@example.com action=register

perform a subquery and a primary query:

logscale
defineTable(query={email=*}, name="emails", include=[email,firstname, lastname])
| match(table="emails", field=loginemail, column=email)

The first query in the pipeline is the subquery used for table definition. The second query in the pipeline is the primary query that uses match().

The following example query combines information about the ProcessRollUp2 and NetworkListenIP4 to find processes that have created listeners on a port.

  1. This is the full query:

    logscale
    defineTable(query={#event_simpleName=NetworkListenIP4 LocalPort<1024 LocalPort!=0}, name="network_listener", include=[ContextProcessId,LocalAddressIP4, LocalPort])
    | #event_simpleName=ProcessRollup2
    | match(table="network_listener",field=TargetProcessId,column=ContextProcessId)
  2. The subquery with defineTable() generates a result table named network_listener:

    ContextProcessId LocalAddressIP4 LocalPort
    123 172.16.254.1 1010
    456 172.19.254.1 2020
    789 190.16.254.1 3030
  3. The second item in the pipeline filters #event_simpleName field to only take the ProcessRollUp2 value.

  4. match() joins the results of the network_listener ad-hoc table with the primary query, by matching:

    • TargetProcessId field from the primary query

    • ContextProcessId column field from the ad-hoc, generated table.

Note

To ensure optimal performance when using defineTable(), follow the best practice described at Ad-hoc Tables Optimization.

For more information on the different methods of creating join queries — including ad-hoc tables with the defineTable() function — see Join Methods.

Important

When using defineTable(), be aware that ad-hoc tables are not supported in Alerts, for the reasons explained at Ad-hoc Tables in Live Queries. Use Scheduled Searches instead.

defineTable() Examples

Click + next to an example below to get the full details.

Perform a Left Join Query to Combine Two Datasets

Perform a Nested Join Query to Combine Two Datasets and Two Tables

Perform a Right Join Query to Combine Two Datasets

Perform an Inner Join Query to Combine Two Datasets

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

Using Ad-hoc Table With CSV File