Method: query.suggest
使用集合让一切井井有条
根据您的偏好保存内容并对其进行分类。
HTTP 请求
POST https://cloudsearch.googleapis.com/v1/query/suggest
网址采用 gRPC 转码语法。
请求正文
请求正文中包含结构如下的数据:
字段 |
requestOptions |
object (RequestOptions )
请求选项,例如搜索应用和用户时区。
|
query |
string
系统将针对该部分查询显示自动补全建议。例如,如果查询是“sea”,则服务器可能会返回“season”“search”“seagull”等。
|
dataSourceRestrictions[] |
object (DataSourceRestriction )
用于提供建议的来源。如果未指定,则数据源会从当前搜索应用中获取。 注意:只有以下来源支持建议功能:
- 第三方数据源
- PredefinedSource.PERSON
- PredefinedSource.GOOGLE_DRIVE
|
响应正文
suggest API 的响应。
如果成功,响应正文将包含结构如下的数据:
字段 |
suggestResults[] |
object (SuggestResult )
建议列表。
|
授权范围
需要以下 OAuth 范围之一:
https://www.googleapis.com/auth/cloud_search.query
https://www.googleapis.com/auth/cloud_search
如需了解详情,请参阅授权指南。
SuggestResult
JSON 表示法 |
{
"suggestedQuery": string,
"source": {
object (Source )
},
// Union field suggestion can be only one of the following:
"querySuggestion": {
object (QuerySuggestion )
},
"peopleSuggestion": {
object (PeopleSuggestion )
}
// End of list of possible types for union field suggestion .
} |
字段 |
suggestedQuery |
string
当用户点击建议时,将用于搜索的建议查询
|
source |
object (Source )
建议的来源。
|
联合字段 suggestion 。包含有关建议的查询的其他元数据。它还会指明建议的查询类型。例如,如果存在 PeopleSuggestion,则表示 suggested_query 是人物建议。suggestion 只能是下列其中一项: |
querySuggestion |
object (QuerySuggestion )
如果建议的查询是字词/短语补全,则此字段会显示。
|
peopleSuggestion |
object (PeopleSuggestion )
当建议指向某个人时,系统会显示此图标。其中包含与该用户相关的更多信息,例如其电子邮件 ID、姓名等。
|
QuerySuggestion
此类型没有字段。
此字段目前不包含任何内容,仅用于指示建议结果是短语补全。
PeopleSuggestion
JSON 表示法 |
{
"person": {
object (Person )
}
} |
字段 |
person |
object (Person )
推荐的联系人。系统可能不会填充人员对象的所有字段。
|
如未另行说明,那么本页面中的内容已根据知识共享署名 4.0 许可获得了许可,并且代码示例已根据 Apache 2.0 许可获得了许可。有关详情,请参阅 Google 开发者网站政策。Java 是 Oracle 和/或其关联公司的注册商标。
最后更新时间 (UTC):2025-07-25。
[null,null,["最后更新时间 (UTC):2025-07-25。"],[],[],null,["# Method: query.suggest\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 - [JSON representation](#body.SuggestResponse.SCHEMA_REPRESENTATION)\n- [Authorization scopes](#body.aspect)\n- [SuggestResult](#SuggestResult)\n - [JSON representation](#SuggestResult.SCHEMA_REPRESENTATION)\n- [QuerySuggestion](#QuerySuggestion)\n- [PeopleSuggestion](#PeopleSuggestion)\n - [JSON representation](#PeopleSuggestion.SCHEMA_REPRESENTATION)\n- [Try it!](#try-it)\n\nProvides suggestions for autocompleting the query.\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/suggest`\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, \"dataSourceRestrictions\": [ { object (/workspace/cloud-search/docs/reference/rest/v1/settings.searchapplications#DataSourceRestriction) } ] } ``` |\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` Partial query for which autocomplete suggestions will be shown. For example, if the query is \"sea\", then the server might return \"season\", \"search\", \"seagull\" and so on. |\n| `dataSourceRestrictions[]` | `object (`[DataSourceRestriction](/workspace/cloud-search/docs/reference/rest/v1/settings.searchapplications#DataSourceRestriction)`)` The sources to use for suggestions. If not specified, the data sources are taken from the current search application. NOTE: Suggestions are only supported for the following sources: - Third-party data sources - PredefinedSource.PERSON - PredefinedSource.GOOGLE_DRIVE |\n\n### Response body\n\nResponse of the suggest API.\n\nIf successful, the response body contains data with the following structure:\n\n| JSON representation |\n|---------------------------------------------------------------------------------------------------------------------------|\n| ``` { \"suggestResults\": [ { object (/workspace/cloud-search/docs/reference/rest/v1/query/suggest#SuggestResult) } ] } ``` |\n\n| Fields ||\n|--------------------|-------------------------------------------------------------------------------------------------------------------------------|\n| `suggestResults[]` | `object (`[SuggestResult](/workspace/cloud-search/docs/reference/rest/v1/query/suggest#SuggestResult)`)` List of suggestions. |\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).\n\nSuggestResult\n-------------\n\nOne suggestion result.\n\n| JSON representation |\n|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|\n| ``` { \"suggestedQuery\": string, \"source\": { object (/workspace/cloud-search/docs/reference/rest/v1/settings.searchapplications#Source) }, // Union field `suggestion` can be only one of the following: \"querySuggestion\": { object (/workspace/cloud-search/docs/reference/rest/v1/query/suggest#QuerySuggestion) }, \"peopleSuggestion\": { object (/workspace/cloud-search/docs/reference/rest/v1/query/suggest#PeopleSuggestion) } // End of list of possible types for union field `suggestion`. } ``` |\n\n| Fields ||\n|--------------------|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|\n| `suggestedQuery` | `string` The suggested query that will be used for search, when the user clicks on the suggestion |\n| `source` | `object (`[Source](/workspace/cloud-search/docs/reference/rest/v1/settings.searchapplications#Source)`)` The source of the suggestion. |\n| Union field `suggestion`. Contains additional metadata about the suggested query. It also indicates the type of the suggested query. For e.g. if PeopleSuggestion is present, it indicates that suggested_query is a person suggestion. `suggestion` can be only one of the following: ||\n| `querySuggestion` | `object (`[QuerySuggestion](/workspace/cloud-search/docs/reference/rest/v1/query/suggest#QuerySuggestion)`)` This field will be present if the suggested query is a word/phrase completion. |\n| `peopleSuggestion` | `object (`[PeopleSuggestion](/workspace/cloud-search/docs/reference/rest/v1/query/suggest#PeopleSuggestion)`)` This is present when the suggestion indicates a person. It contains more information about the person - like their email id, name etc. |\n\nQuerySuggestion\n---------------\n\nThis type has no fields.\nThis field does not contain anything as of now and is just used as an indicator that the suggest result was a phrase completion.\n\nPeopleSuggestion\n----------------\n\nThis field contains information about the person being suggested.\n\n| JSON representation |\n|------------------------------------------------------------------------------------------|\n| ``` { \"person\": { object (/workspace/cloud-search/docs/reference/rest/v1/Person) } } ``` |\n\n| Fields ||\n|----------|--------------------------------------------------------------------------------------------------------------------------------------------------------|\n| `person` | `object (`[Person](/workspace/cloud-search/docs/reference/rest/v1/Person)`)` Suggested person. All fields of the person object might not be populated. |"]]