Method: query.search
使用集合让一切井井有条
根据您的偏好保存内容并对其进行分类。
Cloud Search Query API 提供了搜索方法,该方法会根据用户查询返回最相关的结果。结果可以来自 Google Workspace 应用(例如 Gmail 或 Google 云端硬盘),也可以来自您为第三方编入索引的数据。
注意:此 API 需要使用标准最终用户账号才能执行。服务账号无法直接执行查询 API 请求;如需使用服务账号执行查询,请设置 Google Workspace 全网域授权。
HTTP 请求
POST https://cloudsearch.googleapis.com/v1/query/search
网址采用 gRPC 转码语法。
请求正文
请求正文中包含结构如下的数据:
字段 |
requestOptions |
object (RequestOptions )
请求选项,例如搜索应用和用户时区。
|
query |
string
原始查询字符串。如需查看支持的搜索运算符,请参阅使用运算符缩小搜索范围
|
pageSize |
integer
一页返回的搜索结果数上限。有效值介于 1 到 100 之间(包括这两个数值)。默认值为 10。如果请求的结果数量超过 2000 个,则最小值为 50。
|
start |
integer
结果的起始索引。
|
dataSourceRestrictions[] |
object (DataSourceRestriction )
用于查询的来源。如果未指定,则使用当前搜索应用中的所有数据源。
|
facetOptions[] |
object (FacetOptions )
|
sortOptions |
object (SortOptions )
用于对搜索结果排序的选项
|
queryInterpretationOptions |
object (QueryInterpretationOptions )
用于解释用户查询的选项。
|
contextAttributes[] |
object (ContextAttribute )
请求的上下文属性,将用于调整搜索结果的排名。元素数量上限为 10 个。
|
响应正文
如果成功,则响应正文包含一个 SearchResponse
实例。
授权范围
需要以下 OAuth 范围之一:
https://www.googleapis.com/auth/cloud_search.query
https://www.googleapis.com/auth/cloud_search
如需了解详情,请参阅授权指南。
如未另行说明,那么本页面中的内容已根据知识共享署名 4.0 许可获得了许可,并且代码示例已根据 Apache 2.0 许可获得了许可。有关详情,请参阅 Google 开发者网站政策。Java 是 Oracle 和/或其关联公司的注册商标。
最后更新时间 (UTC):2025-07-25。
[null,null,["最后更新时间 (UTC):2025-07-25。"],[],[],null,["# Method: query.search\n\n- [HTTP request](#body.HTTP_TEMPLATE)\n- [Request body](#body.request_body)\n - [JSON representation](#body.request_body.SCHEMA_REPRESENTATION)\n- [Response body](#body.response_body)\n- [Authorization scopes](#body.aspect)\n- [Try it!](#try-it)\n\nThe 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.\n\n**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](https://developers.google.com/workspace/cloud-search/docs/guides/delegation/).\n\n### HTTP request\n\n`POST https://cloudsearch.googleapis.com/v1/query/search`\n\nThe URL uses [gRPC Transcoding](https://google.aip.dev/127) syntax.\n\n### Request body\n\nThe request body contains data with the following structure:\n\n| JSON representation |\n|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|\n| ``` { \"requestOptions\": { object (/workspace/cloud-search/docs/reference/rest/v1/RequestOptions) }, \"query\": string, \"pageSize\": integer, \"start\": integer, \"dataSourceRestrictions\": [ { object (/workspace/cloud-search/docs/reference/rest/v1/settings.searchapplications#DataSourceRestriction) } ], \"facetOptions\": [ { object (/workspace/cloud-search/docs/reference/rest/v1/settings.searchapplications#FacetOptions) } ], \"sortOptions\": { object (/workspace/cloud-search/docs/reference/rest/v1/settings.searchapplications#SortOptions) }, \"queryInterpretationOptions\": { object (/workspace/cloud-search/docs/reference/rest/v1/QueryInterpretationOptions) }, \"contextAttributes\": [ { object (/workspace/cloud-search/docs/reference/rest/v1/indexing.datasources.items#ContextAttribute) } ] } ``` |\n\n| Fields ||\n|------------------------------|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|\n| `requestOptions` | `object (`[RequestOptions](/workspace/cloud-search/docs/reference/rest/v1/RequestOptions)`)` Request options, such as the search application and user timezone. |\n| `query` | `string` The raw query string. See supported search operators in the [Narrow your search with operators](https://support.google.com/cloudsearch/answer/6172299) |\n| `pageSize` | `integer` 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. |\n| `start` | `integer` Starting index of the results. |\n| `dataSourceRestrictions[]` | `object (`[DataSourceRestriction](/workspace/cloud-search/docs/reference/rest/v1/settings.searchapplications#DataSourceRestriction)`)` The sources to use for querying. If not specified, all data sources from the current search application are used. |\n| `facetOptions[]` | `object (`[FacetOptions](/workspace/cloud-search/docs/reference/rest/v1/settings.searchapplications#FacetOptions)`)` |\n| `sortOptions` | `object (`[SortOptions](/workspace/cloud-search/docs/reference/rest/v1/settings.searchapplications#SortOptions)`)` The options for sorting the search results |\n| `queryInterpretationOptions` | `object (`[QueryInterpretationOptions](/workspace/cloud-search/docs/reference/rest/v1/QueryInterpretationOptions)`)` options to interpret the user query. |\n| `contextAttributes[]` | `object (`[ContextAttribute](/workspace/cloud-search/docs/reference/rest/v1/indexing.datasources.items#ContextAttribute)`)` Context attributes for the request which will be used to adjust ranking of search results. The maximum number of elements is 10. |\n\n### Response body\n\nIf successful, the response body contains an instance of [SearchResponse](/workspace/cloud-search/docs/reference/rest/v1/SearchResponse).\n\n### Authorization scopes\n\nRequires one of the following OAuth scopes:\n\n- `https://www.googleapis.com/auth/cloud_search.query`\n- `https://www.googleapis.com/auth/cloud_search`\n\nFor more information, see the [Authorization guide](/workspace/guides/configure-oauth-consent)."]]