Mostrar índice de administrador
Organízate con las colecciones
Guarda y clasifica el contenido según tus preferencias.
Mostrar los índices de un proyecto de Datastore
Código de ejemplo
A menos que se indique lo contrario, el contenido de esta página está sujeto a la licencia Reconocimiento 4.0 de Creative Commons y las muestras de código están sujetas a la licencia Apache 2.0. Para obtener más información, consulta las políticas del sitio web de Google Developers. Java es una marca registrada de Oracle o sus afiliados.
[[["Es fácil de entender","easyToUnderstand","thumb-up"],["Me ofreció una solución al problema","solvedMyProblem","thumb-up"],["Otro","otherUp","thumb-up"]],[["Es difícil de entender","hardToUnderstand","thumb-down"],["La información o el código de muestra no son correctos","incorrectInformationOrSampleCode","thumb-down"],["Me faltan las muestras o la información que necesito","missingTheInformationSamplesINeed","thumb-down"],["Problema de traducción","translationIssue","thumb-down"],["Otro","otherDown","thumb-down"]],[],[[["\u003cp\u003eThis content provides code samples in C#, Go, Node.js, Python, and Ruby for listing indexes within a Datastore project.\u003c/p\u003e\n"],["\u003cp\u003eEach language's sample demonstrates how to use the respective client library to list and iterate through indexes.\u003c/p\u003e\n"],["\u003cp\u003eThe examples cover how to obtain and display index details, including the index ID, kind, and properties.\u003c/p\u003e\n"],["\u003cp\u003eSetting up Application Default Credentials is necessary for authenticating to Datastore mode, and instructions to do this are provided.\u003c/p\u003e\n"],["\u003cp\u003eThe content also includes links to relevant documentation, including client library installation guides and API reference materials for each language.\u003c/p\u003e\n"]]],[],null,["# List admin index\n\nList indexes within a Datastore project\n\nCode sample\n-----------\n\n### C#\n\n\nTo learn how to install and use the client library for Datastore mode, see\n[Datastore mode client libraries](/datastore/docs/reference/libraries).\n\n\nFor more information, see the\n[Datastore mode C# API\nreference documentation](https://cloud.google.com/dotnet/docs/reference/Google.Cloud.Datastore.V1/latest).\n\n\nTo authenticate to Datastore mode, set up Application Default Credentials.\nFor more information, see\n\n[Set up authentication for a local development environment](/docs/authentication/set-up-adc-local-dev-environment).\n\n\n using https://cloud.google.com/dotnet/docs/reference/Google.Cloud.Datastore.Admin.V1/latest/Google.Cloud.Datastore.Admin.V1.html;\n using System;\n using System.Collections.Generic;\n\n public class ListIndexesSample\n {\n public IEnumerable\u003cGoogle.Cloud.Datastore.Admin.V1.Index\u003e ListIndexes(string projectId = \"your-project-id\")\n {\n // Create client\n https://cloud.google.com/dotnet/docs/reference/Google.Cloud.Datastore.Admin.V1/latest/Google.Cloud.Datastore.Admin.V1.DatastoreAdminClient.html datastoreAdminClient = https://cloud.google.com/dotnet/docs/reference/Google.Cloud.Datastore.Admin.V1/latest/Google.Cloud.Datastore.Admin.V1.DatastoreAdminClient.html.https://cloud.google.com/dotnet/docs/reference/Google.Cloud.Datastore.Admin.V1/latest/Google.Cloud.Datastore.Admin.V1.DatastoreAdminClient.html#Google_Cloud_Datastore_Admin_V1_DatastoreAdminClient_Create();\n\n // Initialize request argument(s)\n https://cloud.google.com/dotnet/docs/reference/Google.Cloud.Datastore.Admin.V1/latest/Google.Cloud.Datastore.Admin.V1.ListIndexesRequest.html listIndexesRequest = new https://cloud.google.com/dotnet/docs/reference/Google.Cloud.Datastore.Admin.V1/latest/Google.Cloud.Datastore.Admin.V1.ListIndexesRequest.html\n {\n ProjectId = projectId\n };\n\n var response = datastoreAdminClient.https://cloud.google.com/dotnet/docs/reference/Google.Cloud.Datastore.Admin.V1/latest/Google.Cloud.Datastore.Admin.V1.DatastoreAdminClient.html#Google_Cloud_Datastore_Admin_V1_DatastoreAdminClient_ListIndexes_Google_Cloud_Datastore_Admin_V1_ListIndexesRequest_Google_Api_Gax_Grpc_CallSettings_(listIndexesRequest);\n\n foreach (var index in response)\n {\n Console.WriteLine($\"Index Id: {index.IndexId}\");\n Console.WriteLine($\"Kind: {index.https://cloud.google.com/dotnet/docs/reference/Google.Cloud.Datastore.Admin.V1/latest/Google.Cloud.Datastore.Admin.V1.Index.html#Google_Cloud_Datastore_Admin_V1_Index_Kind}\");\n\n Console.WriteLine(\"Properties:\");\n foreach (var property in index.https://cloud.google.com/dotnet/docs/reference/Google.Cloud.Datastore.Admin.V1/latest/Google.Cloud.Datastore.Admin.V1.Index.html#Google_Cloud_Datastore_Admin_V1_Index_Properties)\n {\n Console.WriteLine($\"Property: {property.https://cloud.google.com/dotnet/docs/reference/Google.Cloud.Datastore.Admin.V1/latest/Google.Cloud.Datastore.Admin.V1.Index.Types.IndexedProperty.html#Google_Cloud_Datastore_Admin_V1_Index_Types_IndexedProperty_Name}\");\n Console.WriteLine($\"Direction: {property.Direction}\");\n }\n }\n\n return response;\n }\n }\n\n### Go\n\n\nTo learn how to install and use the client library for Datastore mode, see\n[Datastore mode client libraries](/datastore/docs/reference/libraries).\n\n\nFor more information, see the\n[Datastore mode Go API\nreference documentation](https://cloud.google.com/go/docs/reference/cloud.google.com/go/datastore/latest).\n\n\nTo authenticate to Datastore mode, set up Application Default Credentials.\nFor more information, see\n\n[Set up authentication for a local development environment](/docs/authentication/set-up-adc-local-dev-environment).\n\n import (\n \t\"context\"\n \t\"fmt\"\n \t\"io\"\n\n \tadmin \"cloud.google.com/go/datastore/admin/apiv1\"\n \t\"cloud.google.com/go/datastore/admin/apiv1/adminpb\"\n \t\"google.golang.org/api/iterator\"\n )\n\n // indexList lists the indexes.\n func indexList(w io.Writer, projectID string) ([]*adminpb.Index, error) {\n \t// projectID := \"my-project-id\"\n \tctx := context.Background()\n \tclient, err := admin.NewDatastoreAdminClient(ctx)\n \tif err != nil {\n \t\treturn nil, fmt.Errorf(\"admin.NewDatastoreAdminClient: %w\", err)\n \t}\n \tdefer client.https://cloud.google.com/go/docs/reference/cloud.google.com/go/datastore/latest/admin/apiv1.html#cloud_google_com_go_datastore_admin_apiv1_DatastoreAdminClient_Close()\n\n \treq := &adminpb.ListIndexesRequest{\n \t\tProjectId: projectID,\n \t}\n \tit := client.ListIndexes(ctx, req)\n \tvar indices []*adminpb.Index\n \tfor {\n \t\tindex, err := it.Next()\n \t\tif err == iterator.Done {\n \t\t\tbreak\n \t\t}\n \t\tif err != nil {\n \t\t\treturn nil, fmt.Errorf(\"ListIndexes: %w\", err)\n \t\t}\n \t\tindices = append(indices, index)\n \t\tfmt.Fprintf(w, \"Got index: %v\\n\", index.IndexId)\n \t}\n\n \tfmt.Fprintf(w, \"Got lists of indexes\\n\")\n \treturn indices, nil\n }\n\n### Node.js\n\n\nTo learn how to install and use the client library for Datastore mode, see\n[Datastore mode client libraries](/datastore/docs/reference/libraries).\n\n\nFor more information, see the\n[Datastore mode Node.js API\nreference documentation](https://cloud.google.com/nodejs/docs/reference/datastore/latest).\n\n\nTo authenticate to Datastore mode, set up Application Default Credentials.\nFor more information, see\n\n[Set up authentication for a local development environment](/docs/authentication/set-up-adc-local-dev-environment).\n\n const {Datastore} = require('https://cloud.google.com/nodejs/docs/reference/datastore/latest/overview.html');\n const datastore = new https://cloud.google.com/nodejs/docs/reference/datastore/latest/datastore/datastore.html();\n\n async function listIndexes() {\n const [indexes] = await datastore.https://cloud.google.com/nodejs/docs/reference/datastore/latest/datastore/datastore.html();\n\n console.log(`${indexes.length} indexes returned.`);\n\n // Each returned Index object includes metadata about the index.\n const [firstIndex] = indexes;\n console.log('Properties:', firstIndex.https://cloud.google.com/nodejs/docs/reference/datastore/latest/datastore/index.html.properties);\n\n // You may also get Index references as a readable object stream.\n datastore\n .https://cloud.google.com/nodejs/docs/reference/datastore/latest/datastore/datastore.html()\n .on('data', index =\u003e {\n console.log('Properties:', https://cloud.google.com/nodejs/docs/reference/datastore/latest/datastore/datastore.html.https://cloud.google.com/nodejs/docs/reference/datastore/latest/datastore/index.html.properties);\n })\n .on('https://cloud.google.com/nodejs/docs/reference/datastore/latest/datastore/query.html', () =\u003e {\n // All matching Index objects have been returned.\n });\n }\n\n listIndexes();\n\n### Python\n\n\nTo learn how to install and use the client library for Datastore mode, see\n[Datastore mode client libraries](/datastore/docs/reference/libraries).\n\n\nFor more information, see the\n[Datastore mode Python API\nreference documentation](https://cloud.google.com/python/docs/reference/datastore/latest).\n\n\nTo authenticate to Datastore mode, set up Application Default Credentials.\nFor more information, see\n\n[Set up authentication for a local development environment](/docs/authentication/set-up-adc-local-dev-environment).\n\n def list_indexes(project_id):\n \"\"\"Lists the indexes.\"\"\"\n # project_id := \"my-project-id\"\n client = DatastoreAdminClient()\n\n indexes = []\n for index in client.list_indexes({\"project_id\": project_id}):\n indexes.append(index)\n print(\"Got index: %v\\n\", index.index_id)\n\n print(\"Got list of indexes\\n\")\n return indexes\n\n### Ruby\n\n\nTo learn how to install and use the client library for Datastore mode, see\n[Datastore mode client libraries](/datastore/docs/reference/libraries).\n\n\nFor more information, see the\n[Datastore mode Ruby API\nreference documentation](/ruby/docs/reference/google-cloud-datastore/latest).\n\n\nTo authenticate to Datastore mode, set up Application Default Credentials.\nFor more information, see\n\n[Set up authentication for a local development environment](/docs/authentication/set-up-adc-local-dev-environment).\n\n # project_id = \"project-id\"\n indexes = client.list_indexes(project_id: project_id).map do |index|\n puts \"Got index: #{index.index_id}\"\n index\n end\n\n puts \"Got list of indexes\"\n\nWhat's next\n-----------\n\n\nTo search and filter code samples for other Google Cloud products, see the\n[Google Cloud sample browser](/docs/samples?product=datastore)."]]