Custom attributes

Cloud Talent Solution provides several different job attributes out-of-the-box to support the needs of various customers. To gain the best performance from Cloud Talent Solution, it's highly recommended you use the out-of-the-box fields as much as possible.

In addition, Cloud Talent Solution also provides custom attributes to store generic information. Custom attributes are used to provide even more flexibility to allow customers to support their business logic. Custom attributes store either a string or numerical information, and can be filtered against in search queries by setting appropriate filters.

Custom attributes features

  • Define your own custom field name: Define a name for a particular attribute of a job. Set this attribute to be either filterable or non-filterable depending on your needs. Typically, if the UI needs a filterable facet that is not provided out-of-the-box by Cloud Talent Solution a customAttribute can be used to provide the right filtering.
  • Case (in)sensitive search: Each search request can specify whether the search against all custom attributes is case sensitive or case insensitive.
  • Range based filtering: customAttribute search filters can filter jobs between a range of specified numeric values. For example, if a given customAttribute field is used to store the minimum GPA requirements of a job, the customAttribute search filter can be used to return jobs within a certain minimum GPA range, greater than a minimum GPA value, lesser than a minimum GPA value, etc.
  • Cross-field filtering: customAttribute also provides customers of Cloud Talent Solution with the ability to define expressions that filter a combination of custom attributes. For example, a customer has business logic that states they only want jobs that sponsor visas, or telecommute jobs. The customer stores both these fields in a different customAttribute. The customer can then specify a search filter with an expression that defines the logic needed. Only 3 levels of nested expressions are supported.

  • Keyword specific search: Specify a certain customAttribute in the keywordSearchableCustomAttributes of the associated company to ensure search requests that contain a value in the specified customAttribute return the jobs containing this value in that customAttribute.

  • SQL based searches: customAttribute allows you to define boolean-style expressions in the search request. Cloud Talent Solution automatically parses these expressions, applies the filters to the search request, and returns results accordingly. Only 3 levels of nesting of the boolean expressions and at most 2000 characters are allowed.

  • Define custom histogram buckets: Custom attributes allow customers of Cloud Talent Solution to set custom buckets by which histograms can be calculated. For example, you can use a customAttribute to store minimum GPA information, and then create a histogram on this field. You can further create buckets from 3.0 - 3.5, 3.51 - 4.0, etc., to group all the minimum GPAs within these buckets.

Using custom attributes

Create a new job with the customAttribute field (can be used with either numeric or string values):

Go

import (
	"context"
	"fmt"
	"io"

	talent "cloud.google.com/go/talent/apiv4beta1"
	"github.com/gofrs/uuid"
	talentpb "google.golang.org/genproto/googleapis/cloud/talent/v4beta1"
	money "google.golang.org/genproto/googleapis/type/money"
)

// createJobWithCustomAttributes creates a job with custom attributes.
func createJobWithCustomAttributes(w io.Writer, projectID, companyID, jobTitle string) (*talentpb.Job, error) {
	ctx := context.Background()

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

	// requisitionID shoud be the unique ID in your system
	requisitionID := fmt.Sprintf("job-with-custom-attribute-%s", uuid.Must(uuid.NewV4()).String())
	jobToCreate := &talentpb.Job{
		Company:       fmt.Sprintf("projects/%s/companies/%s", projectID, companyID),
		RequisitionId: requisitionID,
		Title:         jobTitle,
		ApplicationInfo: &talentpb.Job_ApplicationInfo{
			Uris: []string{"https://googlesample.com/career"},
		},
		Description:     "Design, devolop, test, deploy, maintain and improve software.",
		LanguageCode:    "en-US",
		PromotionValue:  2,
		EmploymentTypes: []talentpb.EmploymentType{talentpb.EmploymentType_FULL_TIME},
		Addresses:       []string{"Mountain View, CA"},
		CustomAttributes: map[string]*talentpb.CustomAttribute{
			"someFieldString": {
				Filterable:   true,
				StringValues: []string{"someStrVal"},
			},
			"someFieldLong": {
				Filterable: true,
				LongValues: []int64{900},
			},
		},
		CompensationInfo: &talentpb.CompensationInfo{
			Entries: []*talentpb.CompensationInfo_CompensationEntry{
				{
					Type: talentpb.CompensationInfo_BASE,
					Unit: talentpb.CompensationInfo_HOURLY,
					CompensationAmount: &talentpb.CompensationInfo_CompensationEntry_Amount{
						Amount: &money.Money{
							CurrencyCode: "USD",
							Units:        1,
						},
					},
				},
			},
		},
	}

	// Construct a createJob request.
	req := &talentpb.CreateJobRequest{
		Parent: fmt.Sprintf("projects/%s", projectID),
		Job:    jobToCreate,
	}

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

	fmt.Fprintf(w, "Created job with custom attributres: %q\n", resp.GetName())
	fmt.Fprintf(w, "Custom long field has value: %v\n", resp.GetCustomAttributes()["someFieldLong"].GetLongValues())

	return resp, nil
}

Java

For more on installing and creating a Cloud Talent Solution client, see Cloud Talent Solution Client Libraries.

/*
 * Please include the following imports to run this sample.
 *
 * import com.google.cloud.talent.v4beta1.CreateJobRequest;
 * import com.google.cloud.talent.v4beta1.Job;
 * import com.google.cloud.talent.v4beta1.JobServiceClient;
 * import com.google.cloud.talent.v4beta1.TenantName;
 * import com.google.cloud.talent.v4beta1.TenantOrProjectName;
 */

/**
 * Create Job with Custom Attributes
 *
 * @param projectId Your Google Cloud Project ID
 * @param tenantId Identifier of the Tenantd
 */
public static void sampleCreateJob(
    String projectId,
    String tenantId,
    String companyName,
    String requisitionId,
    String languageCode) {
  try (JobServiceClient jobServiceClient = JobServiceClient.create()) {
    // projectId = "Your Google Cloud Project ID";
    // tenantId = "Your Tenant ID (using tenancy is optional)";
    // companyName = "Company name, e.g. projects/your-project/companies/company-id";
    // requisitionId = "Job requisition ID, aka Posting ID. Unique per job.";
    // languageCode = "en-US";
    TenantOrProjectName parent = TenantName.of(projectId, tenantId);
    Job job =
        Job.newBuilder()
            .setCompany(companyName)
            .setRequisitionId(requisitionId)
            .setLanguageCode(languageCode)
            .build();
    CreateJobRequest request =
        CreateJobRequest.newBuilder().setParent(parent.toString()).setJob(job).build();
    Job response = jobServiceClient.createJob(request);
    System.out.printf("Created job: %s\n", response.getName());
  } catch (Exception exception) {
    System.err.println("Failed to create the client due to: " + exception);
  }
}

Node.js

For more on installing and creating a Cloud Talent Solution client, see Cloud Talent Solution Client Libraries.


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

/**
 * Create Job with Custom Attributes
 *
 * @param projectId {string} Your Google Cloud Project ID
 * @param tenantId {string} Identifier of the Tenantd
 */
function sampleCreateJob(projectId, tenantId, companyName, requisitionId, languageCode) {
  const client = new talent.JobServiceClient();
  // const projectId = 'Your Google Cloud Project ID';
  // const tenantId = 'Your Tenant ID (using tenancy is optional)';
  // const companyName = 'Company name, e.g. projects/your-project/companies/company-id';
  // const requisitionId = 'Job requisition ID, aka Posting ID. Unique per job.';
  // const languageCode = 'en-US';
  const formattedParent = client.tenantPath(projectId, tenantId);
  const job = {
    company: companyName,
    requisitionId: requisitionId,
    languageCode: languageCode,
  };
  const request = {
    parent: formattedParent,
    job: job,
  };
  client.createJob(request)
    .then(responses => {
      const response = responses[0];
      console.log(`Created job: ${response.name}`);
    })
    .catch(err => {
      console.error(err);
    });
}

PHP

For more on installing and creating a Cloud Talent Solution client, see Cloud Talent Solution Client Libraries.

require __DIR__ . '/vendor/autoload.php';

use Google\Cloud\Talent\V4beta1\JobServiceClient;
use Google\Cloud\Talent\V4beta1\Job;

/**
 * Create Job with Custom Attributes.
 *
 * @param string $projectId Your Google Cloud Project ID
 * @param string $tenantId  Identifier of the Tenantd
 */
function sampleCreateJob($projectId, $tenantId, $companyName, $requisitionId, $languageCode)
{

    $jobServiceClient = new JobServiceClient();

    // $projectId = 'Your Google Cloud Project ID';
    // $tenantId = 'Your Tenant ID (using tenancy is optional)';
    // $companyName = 'Company name, e.g. projects/your-project/companies/company-id';
    // $requisitionId = 'Job requisition ID, aka Posting ID. Unique per job.';
    // $languageCode = 'en-US';
    $formattedParent = $jobServiceClient->tenantName($projectId, $tenantId);
    $job = new Job();
    $job->setCompany($companyName);
    $job->setRequisitionId($requisitionId);
    $job->setLanguageCode($languageCode);

    try {
        $response = $jobServiceClient->createJob($formattedParent, $job);
        printf('Created job: %s'.PHP_EOL, $response->getName());
    } finally {
        $jobServiceClient->close();
    }

}

Python

For more on installing and creating a Cloud Talent Solution client, see Cloud Talent Solution Client Libraries.


from google.cloud import talent_v4beta1
import six


def sample_create_job(project_id, tenant_id, company_name, requisition_id,
                      language_code):
    """Create Job with Custom Attributes"""

    client = talent_v4beta1.JobServiceClient()

    # project_id = 'Your Google Cloud Project ID'
    # tenant_id = 'Your Tenant ID (using tenancy is optional)'
    # company_name = 'Company name, e.g. projects/your-project/companies/company-id'
    # requisition_id = 'Job requisition ID, aka Posting ID. Unique per job.'
    # language_code = 'en-US'

    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(company_name, six.binary_type):
        company_name = company_name.decode('utf-8')
    if isinstance(requisition_id, six.binary_type):
        requisition_id = requisition_id.decode('utf-8')
    if isinstance(language_code, six.binary_type):
        language_code = language_code.decode('utf-8')
    parent = client.tenant_path(project_id, tenant_id)
    job = {
        'company': company_name,
        'requisition_id': requisition_id,
        'language_code': language_code
    }

    response = client.create_job(parent, job)
    print('Created job: {}'.format(response.name))


Ruby

For more on installing and creating a Cloud Talent Solution client, see Cloud Talent Solution Client Libraries.


 # Create Job with Custom Attributes
 #
 # @param project_id {String} Your Google Cloud Project ID
 # @param tenant_id {String} Identifier of the Tenantd
def sample_create_job(project_id, tenant_id, company_name, requisition_id, language_code)
  # Instantiate a client
  job_client = Google::Cloud::Talent::JobService.new version: :v4beta1

  # project_id = "Your Google Cloud Project ID"
  # tenant_id = "Your Tenant ID (using tenancy is optional)"
  # company_name = "Company name, e.g. projects/your-project/companies/company-id"
  # requisition_id = "Job requisition ID, aka Posting ID. Unique per job."
  # language_code = "en-US"
  formatted_parent = job_client.class.tenant_path(project_id, tenant_id)
  job = {
    company: company_name,
    requisition_id: requisition_id,
    language_code: language_code
  }

  response = job_client.create_job(formatted_parent, job)
  puts "Created job: #{response.name}"

end

By default, the searchJobs and seachJobsForAlert endpoints only search against out-of-the-box fields. If you also need to search against customAttribute fields, use the keywordSearchableJobCustomAttributes field to define a list of custom attributes to search.

For example, if a recruiter wishes to use a customAttribute "customRequisitions" to store the requisition ids of jobs particular to a specific employer, then by setting keywordSearchableJobCustomAttributes to include this field, a regular search conducted by a recruiter for "ABC123" returns all jobs that have the customAttribute "customRequisitions" with a value of "ABC123".

Var denne siden nyttig? Si fra hva du synes:

Send tilbakemelding om ...

Job Search documentation