- HTTP request
- Path parameters
- Query parameters
- Request body
- Response body
- Authorization scopes
- IAM Permissions
- CompletionResult
- RecentSearchResult
- AttributeResult
- Try it!
Completes the specified prefix with keyword suggestions.
This feature is only available for users who have Retail Search enabled. Enable Retail Search on Cloud Console before using this feature.
HTTP request
GET https://retail.googleapis.com/v2beta/{catalog=projects/*/locations/*/catalogs/*}:completeQuery
The URL uses gRPC Transcoding syntax.
Path parameters
Parameters | |
---|---|
catalog
|
Required. Catalog for which the completion is performed. Full resource name of catalog, such as |
Query parameters
query
string
Required. The query used to generate suggestions.
The maximum number of allowed characters is 255.
visitorId
string
Recommended field. A unique identifier for tracking visitors. For example, this could be implemented with an HTTP cookie, which should be able to uniquely identify a visitor on a single device. This unique identifier should not change if the visitor logs in or out of the website.
The field must be a UTF-8 encoded string with a length limit of 128 characters. Otherwise, an INVALID_ARGUMENT error is returned.
languageCodes[]
string
Note that this field applies for user-data
dataset only. For requests with cloud-retail
dataset, setting this field has no effect.
The language filters applied to the output suggestions. If set, it should contain the language of the query. If not set, suggestions are returned without considering language restrictions. This is the BCP-47 language code, such as "en-US" or "sr-Latn". For more information, see Tags for Identifying Languages . The maximum number of language codes is 3.
deviceType
string
The device type context for completion suggestions. We recommend that you leave this field empty.
It can apply different suggestions on different device types, e.g. DESKTOP
, MOBILE
. If it is empty, the suggestions are across all device types.
Supported formats:
-
UNKNOWN_DEVICE_TYPE
-
DESKTOP
-
MOBILE
-
A customized string starts with
OTHER_
, e.g.OTHER_IPHONE
.
dataset
string
Determines which dataset to use for fetching completion. "user-data" will use the dataset imported through CompletionService.ImportCompletionData
. cloud-retail
will use the dataset generated by Cloud Retail based on user events. If left empty, completions will be fetched from the user-data
dataset.
Current supported values:
-
user-data
-
cloud-retail: This option requires enabling auto-learning function first. See guidelines .
maxSuggestions
integer
Completion max suggestions. If left unset or set to 0, then will fallback to the configured value CompletionConfig.max_suggestions
.
The maximum allowed max suggestions is 20. If it is set higher, it will be capped by 20.
enableAttributeSuggestions
boolean
If true, attribute suggestions are enabled and provided in the response.
This field is only available for the cloud-retail
dataset.
entity
string
The entity for customers who run multiple entities, domains, sites, or regions, for example, Google US
, Google Ads
, Waymo
, google.com
, youtube.com
, etc. If this is set, it must be an exact match with UserEvent.entity
to get per-entity autocomplete results. This field will be applied to completionResults
only. It has no effect on the attributeResults
. Also, this entity should be limited to 256 characters, if too long, it will be truncated to 256 characters in both generation and serving time, and may lead to mis-match. To ensure it works, please set the entity with string within 256 characters.
Request body
The request body must be empty.
Response body
Response of the autocomplete query.
If successful, the response body contains data with the following structure:
JSON representation |
---|
{ "completionResults" : [ { object ( |
completionResults[]
object (
CompletionResult
)
Results of the matching suggestions. The result list is ordered and the first result is top suggestion.
attributionToken
string
A unique complete token. This should be included in the UserEvent.completion_detail
for search events resulting from this completion, which enables accurate attribution of complete model performance.
recentSearchResults[]
(deprecated)
object (
RecentSearchResult
)
Deprecated. Matched recent searches of this user. The maximum number of recent searches is 10. This field is a restricted feature. If you want to enable it, contact Retail Search support.
This feature is only available when CompleteQueryRequest.visitor_id
field is set and UserEvent
is imported. The recent searches satisfy the follow rules:
-
They are ordered from latest to oldest.
-
They are matched with
CompleteQueryRequest.query
case insensitively. -
They are transformed to lower case.
-
They are UTF-8 safe.
Recent searches are deduplicated. More recent searches will be reserved when duplication happens.
attributeResults
map (key: string, value: object (
AttributeResult
))
A map of matched attribute suggestions. This field is only available for cloud-retail
dataset.
Current supported keys:
-
brands
-
categories
Authorization scopes
Requires the following OAuth scope:
-
https://www.googleapis.com/auth/cloud-platform
For more information, see the Authentication Overview .
IAM Permissions
Requires the following IAM
permission on the catalog
resource:
-
retail.catalogs.completeQuery
For more information, see the IAM documentation .
CompletionResult
Resource that represents completion results.
JSON representation |
---|
{ "suggestion" : string , "attributes" : { string : { "text" : [ string ] , "numbers" : [ number ] , "searchable" : boolean , "indexable" : boolean } , ... } } |
suggestion
string
The suggestion for the query.
attributes
map (key: string, value: object)
Custom attributes for the suggestion term.
-
For
user-data
, the attributes are additional custom attributes ingested through BigQuery. -
For
cloud-retail
, the attributes are product attributes generated by Cloud Retail. It requiresUserEvent.product_details
is imported properly.
attributes.text[]
string
The textual values of this custom attribute. For example, ["yellow",
"green"]
when the key is "color".
Empty string is not allowed. Otherwise, an INVALID_ARGUMENT error is returned.
Exactly one of text
or numbers
should be set. Otherwise, an INVALID_ARGUMENT error is returned.
attributes.numbers[]
number
The numerical values of this custom attribute. For example, [2.3, 15.4]
when the key is "lengths_cm".
Exactly one of text
or numbers
should be set. Otherwise, an INVALID_ARGUMENT error is returned.
attributes.searchable
(deprecated)
boolean
This field is normally ignored unless AttributesConfig.attribute_config_level
of the Catalog
is set to the deprecated 'PRODUCT_LEVEL_ATTRIBUTE_CONFIG' mode. For information about product-level attribute configuration, see Configuration modes
. If true, custom attribute values are searchable by text queries in SearchService.Search
.
This field is ignored in a UserEvent
.
Only set if type text
is set. Otherwise, a INVALID_ARGUMENT error is returned.
attributes.indexable
(deprecated)
boolean
This field is normally ignored unless AttributesConfig.attribute_config_level
of the Catalog
is set to the deprecated 'PRODUCT_LEVEL_ATTRIBUTE_CONFIG' mode. For information about product-level attribute configuration, see Configuration modes
. If true, custom attribute values are indexed, so that they can be filtered, faceted or boosted in SearchService.Search
.
This field is ignored in a UserEvent
.
See SearchRequest.filter
, SearchRequest.facet_specs
and SearchRequest.boost_spec
for more details.
RecentSearchResult
Deprecated: Recent search of this user.
JSON representation |
---|
{ "recentSearch" : string } |
Fields | |
---|---|
recentSearch
|
The recent search query. |
AttributeResult
Resource that represents attribute results.
JSON representation |
---|
{ "suggestions" : [ string ] } |
Fields | |
---|---|
suggestions[]
|
The list of suggestions for the attribute. |