Notice: important security update for Drive document URLs and resource keys. For more information, refer to Access link-shared files using resource keys

Search query terms and operators

A query string contains the following three parts:

query_term operator values

Where:

  • query_term is the query term or field to search upon.

  • operator specifies the condition for the query term.

  • values are the specific values you want to use to filter your search results.

This reference provides the query terms and operators you can use with the Drive API.

Query operators

This table lists all valid query operators:

Operator Usage
contains The content of one string is present in the other.
= The content of a string or boolean is equal to the other.
!= The content of a string or boolean is not equal to the other.
< A value is less than another.
<= A value is less than or equal to another.
> A value is greater than another.
>= A value is greater than or equal to another.
in An element is contained within a collection.
and Return items that match both queries.
or Return items that match either query.
not Negates a search query.
has A collection contains an element matching the parameters.

File-specific query terms

The following table lists all valid file query terms. For data types and descriptions, refer to the files resource reference.

Query term Valid operators Usage
title contains, =, != Name of the file. Surround with single quotes '. Escape single quotes in queries with \', such as 'Valentine\'s Day'.
fullText contains Text related to the file's content and metadata, including title, description, and indexable text. Whether the 'title', 'description', 'indexableText' properties, or text in the content or metadata of the file matches. Surround with single quotes '. Escape single quotes in queries with \', such as 'Valentine\'s Day'.
mimeType contains, =, != MIME type of the file. Surround with single quotes '. Escape single quotes in queries with \', such as 'Valentine\'s Day'.
modifiedDate <=, <, =, !=, >, >= Date of the last modification of the file. RFC 3339 format, default timezone is UTC, such as 2012-06-04T12:00:00-08:00. Fields of type date are not currently comparable to each other, only to constant dates.
lastViewedByMeDate <=, <, =, !=, >, >= Date that the user last viewed a file. RFC 3339 format, default timezone is UTC, e.g., 2012-06-04T12:00:00-08:00. Fields of type date are not currently comparable to each other, only to constant dates.
trashed =, != Whether the file is in the trash or not. Can be either true or false.
starred =, != Whether the file is starred or not. Can be either true or false.
parents in Whether the parents collection contains the specified ID.
owners in Users who own the file.
writers in Users or groups who have permission to modify the file. See Permissions resource reference.
readers `in Users or groups who have permission to read the file. See Permissions resource reference.
sharedWithMe =, != Files that are in the user's "Shared with me" collection. All file users are in the file's access control list (ACL). Can be either true or false.
properties has Public custom file properties.
visibility =, '!=' The visibility level of the file. Valid values are anyoneCanFind, anyoneWithLink, domainCanFind, domainWithLink, and limited. Surround with single quotes '. Escape single quotes in queries with \', such as 'Valentine\'s Day'.
shortcutDetails.targetId =, != The ID of the item the shortcut points to.

Note the following details for operator and query term combinations:

  • The contains operator only performs prefix matching for a title term. For example, suppose you have a title of HelloWorld, a query of title contains 'Hello' returns a result, but a query of `title contains 'World' doesn't.

  • The contains operator only performs matching on entire string tokens the fullText term. For example, if the full text of a document contains the string "HelloWorld" only the query fullText contains 'HelloWorld' returns a result.

  • The contains operator matches on an exact alphanumeric phrase if it is surrounded by double quotes. For example, if the fullText of a document contains the string "Hello there world", then the query fullText contains '"Hello there"' returns a result, but the query fullText contains '"Hello world"' doesn't. Furthermore, since the search is alphanumeric, if the full text of a document contains the string "Hello_world", then the query fullText contains '"Hello world"' returns a result.

  • The owners, writers and readers terms are indirectly reflected in the Permissions list and refer to the role on the permission.

Shared drive-specific query terms

The following table lists all valid shared drive query terms. For data types and descriptions, see drives resource reference.

Query term Valid Operators Usage Required useDomainAdminAccess setting
createdDate <=, <, =, !=, >, >= Date when the shared drive was created. Use RFC 3339 format, default timezone is UTC, e.g., 2012-06-04T12:00:00-08:00. true
hidden =, != Specifies whether or not the shared drive is hidden. Can be either true or false. false
memberCount <=, <, =, !=, >, >= Number of users and groups that are members of the shared drive. Takes a numerical value. true
name contains, =, != Name of the shared drive. Surround with single quotes '. Escape single quotes in queries with \', such as 'Valentine\'s Day'. true
organizerCount <=, <, =, !=, >, >= Number of users and groups that are organizers of the shared drive. Takes a numerical value. true