This page refers to the
query
parameter that is part of an Explore .
query
can also be used as part of an aggregate table, as described on theaggregate_table
parameter documentation page.
Usage
explore: explore_name { query : query_name { dimensions : [ dimension1, dimension2, ... ] measures : [ measure1, measure2, ... ] label : "Display Name in Field Picker" description : "Information about this query" pivots : [ dimension1, dimension2, ... ] sorts : [ field1 : asc , field2 : desc , ... ] filters : [ field1 : "value1" , field2 : "value2" , ... ] limit : 100 } ... }
Definition
You can use the query
parameter to create modeled analyses for an Explore. The modeled analyses are listed in the Quick Start
section of a blank Explore, or in the Quick Start pop-up after an Explore has already been run. See the Example
section on this page for how it works.
Modeled analyses are helpful to beginner Looker users, since you can specify elements like the dimensions, measures, filters, and pivots that may be the most relevant and insightful.
Defining a query in LookML
Instead of creating the query's LookML from scratch, you can use an Explore to create the query's base LookML for you. For details, see the next section, Getting query LookML from an Explore .
The query
parameter has the following subparameters:
Getting query LookML from an Explore
As a shortcut, Looker developers can borrow the functionality used to generate aggregate_table
LookML from an Explore, then copy the aggregate table query LookML and use it as a starting point for modeled analysis LookML.
When you copy the LookML for an aggregate table, you'll also copy some parameters that you don't want for your modeled query LookML. Specifically, once you copy the aggregate table LookML you need to delete the
aggregate_table
andmaterialization
parameters, since they apply only to aggregate tables. (See theaggregate_table
parameter documentation page for more information about those parameters.)Also, the aggregate table
query
parameter supports only a subset of the parameters that are supported by modeled Explore queries. This means that once you copy the aggregate tablequery
LookML, you can use additional parameters for your modeled query. See the Defining a query in LookML section on this page for a full list of the parameters supported for modeled queries.
To use an Explore to get a base for your modeled query LookML:
- In your Explore, select all of the fields and filters to include in your modeled query.
- Select Runto get the results.
-
Select Get LookMLfrom the Explore Actions gear menu . This option is available for Looker developers only.
-
Select the Aggregate Tabletab.
-
Looker provides the LookML for an Explore refinement for an aggregate table. We can use the aggregate table's
query
LookML and modify that for a modeled Explore query. Copy the LookML and paste it into the associated model file, which is indicated in the comment preceding the Explore refinement. If the Explore is defined in a separate Explore file , and not in a model file, you can add the refinement to the Explore's file instead of the model file.From here, you can modify the aggregate table LookML to use for a modeled query:
-
Keep only the
query
parameter and its subparameters. Delete theaggregate_table
andmaterialization
parameters, since they apply only to aggregate tables. -
Add a name for the query. As shown in the Example section on this page, the syntax is:
query: query_name
-
Optionally, fill in any additional parameters for your modeled query. See the Defining a query in LookML section on this page for a full list of parameters supported for modeled queries.
Example
This example creates an order_count_by_month
modeled query for the order_items
Explore:
explore: +order_items {
query: order_count_by_month {
description: "Number of orders placed by month in 2019"
dimensions: [orders.created_month]
measures: [orders.count]
filters: [orders.created_date: "2019"]
}
}
Users can run the Quick Start analysis from the Quick Startsection of the Order ItemsExplore.