Get admin index

Get admin index

Code sample

C#

To learn how to install and use the client library for Datastore mode, see Datastore mode client libraries. For more information, see the Datastore mode C# API reference documentation.

To authenticate to Datastore mode, set up Application Default Credentials. For more information, see Set up authentication for a local development environment.


using Google.Cloud.Datastore.Admin.V1;
using System;
using Index = Google.Cloud.Datastore.Admin.V1.Index;

public class GetIndexSample
{
    public Index GetIndex(
        string projectId = "your-project-id",
        string indexId = "your-index-id")
    {
        // Create client
        DatastoreAdminClient datastoreAdminClient = DatastoreAdminClient.Create();

        // Initialize request argument(s)
        GetIndexRequest getIndexRequest = new GetIndexRequest
        {
            ProjectId = projectId,
            IndexId = indexId
        };

        Index index = datastoreAdminClient.GetIndex(getIndexRequest);

        Console.WriteLine($"Index Id: {index.IndexId}");
        Console.WriteLine($"Kind: {index.Kind}");
        Console.WriteLine("Properties:");
        foreach (var property in index.Properties)
        {
            Console.WriteLine($"Property: {property.Name}");
            Console.WriteLine($"Direction: {property.Direction}");
        }
        return index;
    }
}

Go

To learn how to install and use the client library for Datastore mode, see Datastore mode client libraries. For more information, see the Datastore mode Go API reference documentation.

To authenticate to Datastore mode, set up Application Default Credentials. For more information, see Set up authentication for a local development environment.

import (
	"context"
	"fmt"
	"io"

	admin "cloud.google.com/go/datastore/admin/apiv1"
	"cloud.google.com/go/datastore/admin/apiv1/adminpb"
)

// indexGet gets an index.
func indexGet(w io.Writer, projectID, indexID string) (*adminpb.Index, error) {
	// projectID := "my-project-id"
	// indexID := "my-index"
	ctx := context.Background()
	client, err := admin.NewDatastoreAdminClient(ctx)
	if err != nil {
		return nil, fmt.Errorf("admin.NewDatastoreAdminClient: %w", err)
	}
	defer client.Close()

	req := &adminpb.GetIndexRequest{
		ProjectId: projectID,
		IndexId:   indexID,
	}
	index, err := client.GetIndex(ctx, req)
	if err != nil {
		return nil, fmt.Errorf("client.GetIndex: %w", err)
	}

	fmt.Fprintf(w, "Got index: %v\n", index.IndexId)
	return index, nil
}

Python

To learn how to install and use the client library for Datastore mode, see Datastore mode client libraries. For more information, see the Datastore mode Python API reference documentation.

To authenticate to Datastore mode, set up Application Default Credentials. For more information, see Set up authentication for a local development environment.

def get_index(project_id, index_id):
    """Gets an index."""
    # project_id := "my-project-id"
    # index_id := "my-index"
    client = DatastoreAdminClient()
    index = client.get_index({"project_id": project_id, "index_id": index_id})

    print("Got index: %v\n", index.index_id)
    return index

Ruby

To learn how to install and use the client library for Datastore mode, see Datastore mode client libraries. For more information, see the Datastore mode Ruby API reference documentation.

To authenticate to Datastore mode, set up Application Default Credentials. For more information, see Set up authentication for a local development environment.

# project_id = "project-id"
# index_id = "my-index"
index = client.get_index project_id: project_id, index_id: index_id
puts "Got index: #{index.index_id}"

What's next

To search and filter code samples for other Google Cloud products, see the Google Cloud sample browser.