Automatically complete job title (v4beta1)

Automatically complete a job title query.

Documentation pages that include this code sample

To view the code sample used in context, see the following documentation:

Code sample


public static object CompleteQuery(string projectId, string tenantId, string query)
    CompletionClient completionClient = CompletionClient.Create();
    TenantName tenant = TenantName.FromProjectTenant(projectId, tenantId);
    CompleteQueryRequest request = new CompleteQueryRequest
        ParentAsTenantName = tenant,
        Query = query, // partial text for job title
        PageSize = 5, // limit for number of results
        LanguageCodes = { "en-US" } // language code
    var response = completionClient.CompleteQuery(request);
    foreach (var result in response.CompletionResults)
        Console.WriteLine($"Suggested title: {result.Suggestion}");
        // Suggestion type is JOB_TITLE or COMPANY_TITLE
        Console.WriteLine($"Suggestion type: {result.Type}");

    return 0;


import (

	talent ""
	talentpb ""

// jobTitleAutoComplete suggests the job titles of the given
// company identifier on query.
func jobTitleAutocomplete(w io.Writer, projectID, query string) (*talentpb.CompleteQueryResponse, error) {
	ctx := context.Background()

	// Initialize a completionService client.
	c, err := talent.NewCompletionClient(ctx)
	if err != nil {
		return nil, fmt.Errorf("talent.NewCompletionClient: %v", err)

	// Construct a completeQuery request.
	req := &talentpb.CompleteQueryRequest{
		Parent:        fmt.Sprintf("projects/%s", projectID),
		Query:         query,
		LanguageCodes: []string{"en-US"},
		PageSize:      5, // Number of completion results returned.
		Scope:         talentpb.CompleteQueryRequest_PUBLIC,
		Type:          talentpb.CompleteQueryRequest_JOB_TITLE,

	resp, err := c.CompleteQuery(ctx, req)
	if err != nil {
		return nil, fmt.Errorf("CompleteQuery(%s): %v", query, err)

	fmt.Fprintf(w, "Auto complete results:")
	for _, c := range resp.GetCompletionResults() {
		fmt.Fprintf(w, "\t%v\n", c.Suggestion)

	return resp, nil



public class JobSearchAutoCompleteJobTitle {

  public static void completeQuery() throws IOException {
    // TODO(developer): Replace these variables before running the sample.
    String projectId = "your-project-id";
    String tenantId = "your-tenant-id";
    String query = "your-query-for-job-title";
    completeQuery(projectId, tenantId, query);

  // Complete job title given partial text (autocomplete).
  public static void completeQuery(String projectId, String tenantId, String query)
      throws IOException {
    // Initialize client that will be used to send requests. This client only needs to be created
    // once, and can be reused for multiple requests. After completing all of your requests, call
    // the "close" method on the client to safely clean up any remaining background resources.
    try (CompletionClient completionClient = CompletionClient.create()) {
      TenantName parent = TenantName.of(projectId, tenantId);
      CompleteQueryRequest request =
              .setPageSize(5) // limit for number of results
              .addLanguageCodes("en-US") // language code
      CompleteQueryResponse response = completionClient.completeQuery(request);
      for (CompleteQueryResponse.CompletionResult result : response.getCompletionResultsList()) {
        System.out.format("Suggested title: %s%n", result.getSuggestion());
        // Suggestion type is JOB_TITLE or COMPANY_TITLE
        System.out.format("Suggestion type: %s%n", result.getType());


const talent = require('@google-cloud/talent').v4;

 * Complete job title given partial text (autocomplete)
 * @param projectId {string} Your Google Cloud Project ID
 * @param tenantId {string} Identifier of the TenantId
function sampleCompleteQuery(
) {
  const client = new talent.CompletionClient();
  // const projectId = 'Your Google Cloud Project ID';
  // const tenantId = 'Your Tenant ID (using tenancy is optional)';
  // const query = '[partially typed job title]';
  // const numResults = 5;
  // const languageCode = 'en-US';
  const formattedParent = client.tenantPath(projectId, tenantId);
  const languageCodes = [languageCode];
  const request = {
    parent: formattedParent,
    query: query,
    pageSize: numResults,
    languageCodes: languageCodes,
    .then(responses => {
      const response = responses[0];
      for (const result of response.completionResults) {
        console.log(`Suggested title: ${result.suggestion}`);
        // Suggestion type is JOB_TITLE or COMPANY_TITLE
        console.log(`Suggestion type: ${result.type}`);
    .catch(err => {


from import talent_v4beta1
import six

def complete_query(project_id, tenant_id, query):
    """Complete job title given partial text (autocomplete)"""

    client = talent_v4beta1.CompletionClient()

    # project_id = 'Your Google Cloud Project ID'
    # tenant_id = 'Your Tenant ID (using tenancy is optional)'
    # query = '[partially typed job title]'

    if isinstance(project_id, six.binary_type):
        project_id = project_id.decode("utf-8")
    if isinstance(tenant_id, six.binary_type):
        tenant_id = tenant_id.decode("utf-8")
    if isinstance(query, six.binary_type):
        query = query.decode("utf-8")

    parent = f"projects/{project_id}/tenants/{tenant_id}"

    request = talent_v4beta1.CompleteQueryRequest(
        page_size=5,  # limit for number of results
        language_codes=["en-US"],  # language code
    response = client.complete_query(request=request)
    for result in response.completion_results:
        print(f"Suggested title: {result.suggestion}")
        # Suggestion type is JOB_TITLE or COMPANY_TITLE
            f"Suggestion type: {talent_v4beta1.CompleteQueryRequest.CompletionType(result.type_).name}"


require "google/cloud/talent"

# Instantiate a client
completion_service = Google::Cloud::Talent.completion

# project_id = "Your Google Cloud Project ID"
# tenant_id = "Your Tenant ID (using tenancy is required)"
formatted_parent = completion_service.tenant_path project: project_id, tenant: tenant_id

# language_code = "en-US"
language_codes = [language_code]

# query = "[partially typed job title]"
# page_size: page_size = 5
response = completion_service.complete_query tenant:         formatted_parent,
                                             query:          query,
                                             page_size:      page_size,
                                             language_codes: language_codes

response.completion_results.each do |result|
  puts "Suggested title: #{result.suggestion}"
  # Suggestion type is JOB_TITLE or COMPANY_NAME
  puts "Suggestion type: #{result.type}"