2121import com .google .cloud .discoveryengine .v1 .SearchRequest ;
2222import com .google .cloud .discoveryengine .v1 .SearchResponse ;
2323import com .google .cloud .discoveryengine .v1 .SearchServiceClient ;
24+ import com .google .cloud .discoveryengine .v1 .SearchServiceSettings ;
2425import com .google .cloud .discoveryengine .v1 .ServingConfigName ;
2526import java .io .IOException ;
2627import java .util .concurrent .ExecutionException ;
@@ -30,38 +31,45 @@ public static void main() throws IOException, ExecutionException {
3031 // TODO(developer): Replace these variables before running the sample.
3132 // Project ID or project number of the Cloud project you want to use.
3233 String projectId = "PROJECT_ID" ;
33- // Location of the search engine . Options: "global"
34+ // Location of the data store . Options: "global", "us", "eu "
3435 String location = "global" ;
35- // Collection containing the datastore .
36+ // Collection containing the data store .
3637 String collectionId = "default_collection" ;
37- // Datastore/Search Engine ID.
38- String searchEngineId = "DATA_STORE_ID" ;
38+ // Data store ID.
39+ String dataStoreId = "DATA_STORE_ID" ;
3940 // Serving configuration. Options: "default_search"
4041 String servingConfigId = "default_search" ;
41- // Search Query for the search engine .
42+ // Search Query for the data store .
4243 String searchQuery = "Google" ;
43- search (projectId , location , collectionId , searchEngineId , servingConfigId , searchQuery );
44+ search (projectId , location , collectionId , dataStoreId , servingConfigId , searchQuery );
4445 }
4546
46- /** Performs a search on a given datastore/search engine . */
47+ /** Performs a search on a given datastore. */
4748 public static void search (
4849 String projectId ,
4950 String location ,
5051 String collectionId ,
51- String searchEngineId ,
52+ String dataStoreId ,
5253 String servingConfigId ,
5354 String searchQuery )
5455 throws IOException , ExecutionException {
56+ // For more information, refer to:
57+ // https://cloud.google.com/generative-ai-app-builder/docs/locations#specify_a_multi-region_for_your_data_store
58+ String endpoint = (location .equals ("global" ))
59+ ? String .format ("discoveryengine.googleapis.com:443" , location )
60+ : String .format ("%s-discoveryengine.googleapis.com:443" , location );
61+ SearchServiceSettings settings =
62+ SearchServiceSettings .newBuilder ().setEndpoint (endpoint ).build ();
5563 // Initialize client that will be used to send requests. This client only needs to be created
5664 // once, and can be reused for multiple requests. After completing all of your requests, call
5765 // the `searchServiceClient.close()` method on the client to safely
5866 // clean up any remaining background resources.
59- try (SearchServiceClient searchServiceClient = SearchServiceClient .create ()) {
67+ try (SearchServiceClient searchServiceClient = SearchServiceClient .create (settings )) {
6068 SearchRequest request =
6169 SearchRequest .newBuilder ()
6270 .setServingConfig (
6371 ServingConfigName .formatProjectLocationCollectionDataStoreServingConfigName (
64- projectId , location , collectionId , searchEngineId , servingConfigId ))
72+ projectId , location , collectionId , dataStoreId , servingConfigId ))
6573 .setQuery (searchQuery )
6674 .setPageSize (10 )
6775 .build ();
0 commit comments