- HTTP request
- Request body
- Response body
- Authorization Scopes
- QueryInterpretationOptions
- QueryInterpretation
- QueryInterpretation.InterpretationType
- QueryInterpretation.Reason
- SearchResult
- Snippet
- MatchRange
- Metadata
- ResultDisplayMetadata
- ResultDisplayMetadata.ResultDisplayLine
- ResultDisplayMetadata.ResultDisplayField
- ResultDebugInfo
- StructuredResult
- SpellResult
- FacetResult
- FacetBucket
- ResponseDebugInfo
- ErrorInfo
- ErrorMessage
- ResultCounts
- SourceResultCount
- Try it!
The Cloud Search Query API provides the search method, which returns the most relevant results from a user query. The results can come from Google Workspace apps, such as Gmail or Google Drive, or they can come from data that you have indexed from a third party.
Note: This API requires a standard end user account to execute. A service account can't perform Query API requests directly; to use a service account to perform queries, set up Google Workspace domain-wide delegation of authority.
HTTP request
POST https://cloudsearch.googleapis.com/v1/query/search
The URL uses gRPC Transcoding syntax.
Request body
The request body contains data with the following structure:
JSON representation |
---|
{ "requestOptions": { object ( |
Fields | |
---|---|
requestOptions |
Request options, such as the search application and user timezone. |
query |
The raw query string. See supported search operators in the Narrow your search with operators |
pageSize |
Maximum number of search results to return in one page. Valid values are between 1 and 100, inclusive. Default value is 10. Minimum value is 50 when results beyond 2000 are requested. |
start |
Starting index of the results. |
dataSourceRestrictions[] |
The sources to use for querying. If not specified, all data sources from the current search application are used. |
facetOptions[] |
|
sortOptions |
The options for sorting the search results |
queryInterpretationOptions |
options to interpret the user query. |
contextAttributes[] |
Context attributes for the request which will be used to adjust ranking of search results. The maximum number of elements is 10. |
Response body
If successful, the response body contains data with the following structure:
The search API response.
JSON representation |
---|
{ "queryInterpretation": { object ( |
Fields | |
---|---|
queryInterpretation |
Query interpretation result for user query. Empty if query interpretation is disabled. |
results[] |
Results from a search query. |
structuredResults[] |
Structured results for the user query. These results are not counted against the pageSize. |
spellResults[] |
Suggested spelling for the query. |
facetResults[] |
Repeated facet results. |
hasMoreResults |
Whether there are more search results matching the query. |
debugInfo |
Debugging information about the response. |
errorInfo |
Error information about the response. |
resultCounts |
Expanded result count information. |
Union field
In the rare case when the system is unable to search through all documents, rerun the query. |
|
resultCountEstimate |
The estimated result count for this query. |
resultCountExact |
The exact result count for this query. |
Authorization Scopes
Requires one of the following OAuth scopes:
https://www.googleapis.com/auth/cloud_search.query
https://www.googleapis.com/auth/cloud_search
For more information, see the Authorization guide.
QueryInterpretationOptions
options to interpret user query.
JSON representation |
---|
{ "disableNlInterpretation": boolean, "enableVerbatimMode": boolean, "disableSupplementalResults": boolean } |
Fields | |
---|---|
disableNlInterpretation |
Flag to disable natural language (NL) interpretation of queries. Default is false, Set to true to disable natural language interpretation. NL interpretation only applies to predefined datasources. |
enableVerbatimMode |
Enable this flag to turn off all internal optimizations like natural language (NL) interpretation of queries, supplemental result retrieval, and usage of synonyms including custom ones. Nl interpretation will be disabled if either one of the two flags is true. |
disableSupplementalResults |
Use this flag to disable supplemental results for a query. Supplemental results setting chosen at SearchApplication level will take precedence if set to True. |
QueryInterpretation
JSON representation |
---|
{ "interpretedQuery": string, "interpretationType": enum ( |
Fields | |
---|---|
interpretedQuery |
The interpretation of the query used in search. For example, queries with natural language intent like "email from john" will be interpreted as "from:john source:mail". This field will not be filled when the reason is NOT_ENOUGH_RESULTS_FOUND_FOR_USER_QUERY. |
interpretationType |
|
reason |
The reason for interpretation of the query. This field will not be UNSPECIFIED if the interpretation type is not NONE. |
QueryInterpretation.InterpretationType
Enums | |
---|---|
NONE |
Neither the natural language interpretation, nor a broader version of the query is used to fetch the search results. |
BLEND |
The results from original query are blended with other results. The reason for blending these other results with the results from original query is populated in the 'Reason' field below. |
REPLACE |
The results from original query are replaced. The reason for replacing the results from original query is populated in the 'Reason' field below. |
QueryInterpretation.Reason
Enums | |
---|---|
UNSPECIFIED |
|
QUERY_HAS_NATURAL_LANGUAGE_INTENT |
Natural language interpretation of the query is used to fetch the search results. |
NOT_ENOUGH_RESULTS_FOUND_FOR_USER_QUERY |
Query and document terms similarity is used to selectively broaden the query to retrieve additional search results since enough results were not found for the user query. Interpreted query will be empty for this case. |
SearchResult
Results containing indexed information for a document.
JSON representation |
---|
{ "title": string, "url": string, "snippet": { object ( |
Fields | |
---|---|
title |
Title of the search result. |
url |
The URL of the search result. The URL contains a Google redirect to the actual item. This URL is signed and shouldn't be changed. |
snippet |
The concatenation of all snippets (summaries) available for this result. |
metadata |
metadata of the search result. |
clusteredResults[] |
If source is clustered, provide list of clustered results. There will only be one level of clustered results. If current source is not enabled for clustering, this field will be empty. |
debugInfo |
Debugging information about this search result. |
Snippet
Snippet of the search result, which summarizes the content of the resulting page.
JSON representation |
---|
{
"snippet": string,
"matchRanges": [
{
object ( |
Fields | |
---|---|
snippet |
The snippet of the document. The snippet of the document. May contain escaped HTML character that should be unescaped prior to rendering. |
matchRanges[] |
The matched ranges in the snippet. |
MatchRange
Matched range of a snippet [start, end).
JSON representation |
---|
{ "start": integer, "end": integer } |
Fields | |
---|---|
start |
Starting position of the match in the snippet. |
end |
End of the match in the snippet. |
Metadata
metadata of a matched search result.
JSON representation |
---|
{ "source": { object ( |
Fields | |
---|---|
source |
The named source for the result, such as Gmail. |
mimeType |
Mime type of the search result. |
thumbnailUrl |
The thumbnail URL of the result. |
owner |
owner (usually creator) of the document or object of the search result. |
createTime |
The creation time for this document or object in the search result. A timestamp in RFC3339 UTC "Zulu" format, with nanosecond resolution and up to nine fractional digits. Examples: |
updateTime |
The last modified date for the object in the search result. If not set in the item, the value returned here is empty. When A timestamp in RFC3339 UTC "Zulu" format, with nanosecond resolution and up to nine fractional digits. Examples: |
fields[] |
Indexed fields in structured data, returned as a generic named property. |
displayOptions |
options that specify how to display a structured data search result. |
objectType |
Object type of the search result. |
ResultDisplayMetadata
JSON representation |
---|
{
"objectTypeLabel": string,
"metalines": [
{
object ( |
Fields | |
---|---|
objectTypeLabel |
The display label for the object. |
metalines[] |
The metalines content to be displayed with the result. |
ResultDisplayMetadata.ResultDisplayLine
The collection of fields that make up a displayed line
JSON representation |
---|
{
"fields": [
{
object ( |
Fields | |
---|---|
fields[] |
ResultDisplayMetadata.ResultDisplayField
Display Fields for query.search Results
JSON representation |
---|
{
"label": string,
"operatorName": string,
"property": {
object ( |
Fields | |
---|---|
label |
The display label for the property. |
operatorName |
The operator name of the property. |
property |
The name value pair for the property. |
ResultDebugInfo
Debugging information about the result.
JSON representation |
---|
{ "formattedDebugInfo": string } |
Fields | |
---|---|
formattedDebugInfo |
General debug info formatted for display. |
StructuredResult
Structured results that are returned as part of search request.
JSON representation |
---|
{
"person": {
object ( |
Fields | |
---|---|
person |
Representation of a person |
SpellResult
JSON representation |
---|
{ "suggestedQuery": string } |
Fields | |
---|---|
suggestedQuery |
The suggested spelling of the query. |
FacetResult
Source specific facet response
JSON representation |
---|
{
"sourceName": string,
"objectType": string,
"operatorName": string,
"buckets": [
{
object ( |
Fields | |
---|---|
sourceName |
Source name for which facet results are returned. Will not be empty. |
objectType |
Object type for which facet results are returned. Can be empty. |
operatorName |
The name of the operator chosen for faceting. @see cloudsearch.SchemaPropertyOptions |
buckets[] |
FacetBuckets for values in response containing at least a single result with the corresponding filter. |
FacetBucket
A bucket in a facet is the basic unit of operation. A bucket can comprise either a single value OR a contiguous range of values, depending on the type of the field bucketed. FacetBucket is currently used only for returning the response object.
JSON representation |
---|
{ "count": integer, "percentage": integer, "filter": { object ( |
Fields | |
---|---|
count |
Number of results that match the bucket value. Counts are only returned for searches when count accuracy is ensured. Cloud Search does not guarantee facet counts for any query and facet counts might be present only intermittently, even for identical queries. Do not build dependencies on facet count existence; instead use facet ount percentages which are always returned. |
percentage |
Percent of results that match the bucket value. The returned value is between (0-100], and is rounded down to an integer if fractional. If the value is not explicitly returned, it represents a percentage value that rounds to 0. Percentages are returned for all searches, but are an estimate. Because percentages are always returned, you should render percentages instead of counts. |
filter |
Filter to be passed in the search request if the corresponding bucket is selected. |
value |
|
ResponseDebugInfo
Debugging information about the response.
JSON representation |
---|
{ "formattedDebugInfo": string } |
Fields | |
---|---|
formattedDebugInfo |
General debug info formatted for display. |
ErrorInfo
Error information about the response.
JSON representation |
---|
{
"errorMessages": [
{
object ( |
Fields | |
---|---|
errorMessages[] |
|
ErrorMessage
Error message per source response.
JSON representation |
---|
{
"source": {
object ( |
Fields | |
---|---|
source |
|
errorMessage |
|
ResultCounts
Result count information
JSON representation |
---|
{
"sourceResultCounts": [
{
object ( |
Fields | |
---|---|
sourceResultCounts[] |
Result count information for each source with results. |
SourceResultCount
Per source result count information.
JSON representation |
---|
{ "source": { object ( |
Fields | |
---|---|
source |
The source the result count information is associated with. |
hasMoreResults |
Whether there are more search results for this source. |
Union field
|
|
resultCountEstimate |
The estimated result count for this source. |
resultCountExact |
The exact result count for this source. |