Adjust result size

This page provides an overview of query expansion.

Query expansion tutorial

This tutorial shows you how to enable the query expansion feature. When a shopper uses an ambiguous or a multi-word search phrase, they can get an empty response. After turning on query expansion, Retail Search analyzes the request and returns the expanded list of products based on the parsed search query.

To follow step-by-step guidance for this task directly in the Cloud Shell Editor, click Guide me:

Guide me

Example dataset

This page uses the following dataset as an example. Only the fields necessary for explanation are included.

Query expansion

Query expansion increases the recall for query terms with few results, especially long tail queries.



public static void searchProductsWithQueryExpansion(String query, int pageSize,
    Condition condition) throws IOException, InterruptedException {
  QueryExpansionSpec queryExpansionSpec = QueryExpansionSpec.newBuilder()

  SearchRequest searchRequest = SearchRequest.newBuilder()

  try (SearchServiceClient searchClient = SearchServiceClient.create()) {
    SearchResponse response =;
    System.out.println("Search response: " + searchResponse);

For example, if you search "Google Pixel 5" without query expansion, you might only get "google_pixel_5" in the result. With query expansion, you might get "google_pixel_4a_with_5g", "google_pixel_4a" and "google_pixel_5_case" as well.