You must configure access to the Google Cloud Search API before you can use this API either directly or through an SDK. This document covers the steps required to use the Google Cloud Search API REST API.
1. Create an API project
To enable the API, you must first create an Google Cloud project. This project forms the basis for creating, enabling, and using all Google Cloud services, including managing APIs, enabling billing, adding and removing collaborators, and managing permissions.
Open the Google Cloud console.
At the top of the page, click
to the right of "Google Cloud Console." A dialog listing current projects appears.Click NEW PROJECT. The "New Project" screen appears.
Enter a project name in the Project Name field.
(optional) Click Edit to edit the Project ID. The project ID can't be changed after the project is created, so choose an ID that meets your needs for the lifetime of the project.
To browse locations for the project, click BROWSE.
Click on a location for your project and click Select.
Click Create. The console navigates to the Dashboard page. The project is created within a few minutes.
For further information on creating and managing projects, refer to Creating and Managing Projects.
2. Enable the API
You need to enable the Google Cloud Search API and create a service account to obtain credentials.
- To ensure you are on the newly created project, click the icon to the right of the Google Cloud console banner and select your newly-created project.
- Click ENABLE APIS AND SERVICES. The "Welcome to API Library" page appears.
- Navigate to the Google Cloud Search API.
- Click Enable. The "Overview" page appears.
For further information on enabling and disabling APIs, refer to Manage APIs in the Google Cloud console
3. Create service account credentials
- In the Google Cloud console, click Credentials in the left navigation. The Credential page appears.
- From the Create credentials drop-down list, select Service account. The "Create service account" page appears.
- Enter a name in the Service account name field.
- (optional) Edit the service account ID.
- Click Create. A "Service account permissions" screen appears.
- Click Continue. A "Grant users access to this service account" screen appears.
- Click CREATE KEY and click Done. A "Private key saved to your computer" dialog appears and a copy of the private key downloads to your computer.
- Click Close.
For further information on service accounts, refer to Service accounts, web applications, and installed applications
4. Identify email address
- From the Google Cloud console, select the project you created at the top of the page.
- Click the Navigation menu to the left of the Google Cloud console banner.
- Click IAM and Admin > Service accounts.
- In the list, under "Service account ID," make note of the generated email address that identifies the service account you configured. This email address is used when adding a data source to Cloud Search.
5. Initialize third-party support
Before you can call any other Cloud Search APIs, you must initialize third-party support for Google Cloud Search.
To initialize third-party support for Cloud Search:
Your Cloud Search platform project contains service account credentials. However, for the sake of initializing third-party support, you must create web application credentials. For instructions on how to create web application credentials, refer to Create credentials. Upon completing this step, you should have a client ID and client secret file.
Use Google's OAuth 2 playground to obtain an access token:
- Click settings and check User your own auth credentials.
- Enter the client ID and client secret from step 1.
- Click Close.
- In the scopes field, type
https://www.googleapis.com/auth/cloud_search.settings
and click Authorize. The OAuth 2 playground returns an authorization code. - Click Exchange authorization code for tokens. A token is returned.
To initialize third-party support for Cloud Search, use the following curl command. Be sure to substitute
[YOUR_ACCESS_TOKEN]
with the token obtained in step 2.curl --request POST \ 'https://cloudsearch.googleapis.com/v1:initializeCustomer' \ --header 'Authorization: Bearer [YOUR_ACCESS_TOKEN]' \ --header 'Accept: application/json' \ --header 'Content-Type: application/json' \ --data '{}' \ --compressed
If successful, the response body contains an instance of
operation
. For example:{ name: "operations/customers/01b3fqdm/lro/AOIL6eBv7fEfiZ_hUSpm8KQDt1Mnd6dj5Ru3MXf-jri4xK6Pyb2-Lwfn8vQKg74pgxlxjrY" }
If unsuccessful, contact Cloud Search support.
Use operations.get to verify that third-party support is initialized:
curl \ 'https://cloudsearch.googleapis.com/v1/operations/customers/01b3fqdm/lro/AOIL6eBv7fEfiZ_hUSpm8KQDt1Mnd6dj5Ru3MXf-jri4xK6Pyb2-Lwfn8vQKg74pgxlxjrY?key= [YOUR_API_KEY]' \ --header 'Authorization: Bearer [YOUR_ACCESS_TOKEN]' \ --header 'Accept: application/json' \ --compressed
When the third-party initialization is complete, it contains the field
done
set totrue
. For example:{ name: "operations/customers/01b3fqdm/lro/AOIL6eBv7fEfiZ_hUSpm8KQDt1Mnd6dj5Ru3MXf-jri4xK6Pyb2-Lwfn8vQKg74pgxlxjrY" done: true }
Next Steps
Here are few next steps you might take:
If you plan on using Google Cloud Search with a non-Google data repository, such as Microsoft® SharePoint®, you must create a data source. For instructions on adding a data source, refer to Add a data source to search.
Once you set up your data source, you can create and register schema to identify how Google Cloud Search should represent the data in the repository.