O MetaSearch indexa metadados de objetos no OSS e permite filtrar e recuperar objetos com base em condições personalizadas.
Casos de uso
Auditoria de dados
Localize arquivos rapidamente para auditorias de dados ou conformidade regulatória. No setor financeiro, por exemplo, filtre por tags personalizadas e permissões de acesso para encontrar arquivos com níveis específicos de sensibilidade.
Backup e arquivamento de dados corporativos
Recupere arquivos por data ou tipo durante processos de backup e arquivamento. Filtre por hora de criação, classe de armazenamento ou tags personalizadas para localizar registros históricos ou arquivados.
Limitações
-
Limite de região
O MetaSearch está disponível nas seguintes regiões: China (Hangzhou), China (Shanghai), China (Qingdao), China (Beijing), China (Zhangjiakou), China (Shenzhen), China (Guangzhou), China (Chengdu), China (Ulanqab), China (Hong Kong), Singapura, Indonésia (Jacarta), Alemanha (Frankfurt), EUA (Virgínia), EUA (Vale do Silício) e Reino Unido (Londres).
-
Limite de bucket
Um bucket com o MetaSearch ativado pode conter até 50 bilhões de objetos. Exceder esse limite pode degradar o desempenho da recuperação. Para processar volumes maiores de dados, entre em contato com a Suporte Técnico para uma avaliação.
-
Upload multipart
Para objetos criados via upload multipart, os resultados da consulta exibem apenas objetos completos montados pela operação CompleteMultipartUpload, excluindo partes de upload incompletas ou abortadas.
Desempenho
As métricas abaixo servem apenas como referência.
-
Tempo de geração de índice para arquivos existentes
100 milhões de arquivos em um único bucket: 4 horas
1 bilhão de arquivos em um único bucket: cerca de 10 horas
10 bilhões de arquivos em um único bucket: cerca de 1 a 3 dias
20 bilhões de arquivos em um único bucket: cerca de 2 a 4 dias
30 bilhões de arquivos em um único bucket: cerca de 3 a 6 dias
50 bilhões de arquivos em um único bucket: cerca de 6 a 10 dias
Se o bucket contiver mais de 1 bilhão de arquivos com tags, a geração do índice levará mais tempo do que as estimativas acima.
-
Tempo de atualização incremental do índice de arquivos
Por padrão, o OSS aloca 5.000 QPS para o MetaSearch atualizar índices, independentemente do QoS do bucket. Quando a taxa de adição, modificação ou exclusão de arquivos permanece abaixo de 5.000, as atualizações geralmente tornam-se pesquisáveis em minutos. Caso a taxa exceda 5.000 QPS, entre em contato com a Suporte Técnico para obter assistência.
-
Desempenho de recuperação de arquivos
A recuperação é concluída em segundos, com um tempo limite padrão de 30 segundos.
Ativar o MetaSearch
OSS console
Para buckets em China (Hangzhou), China (Shanghai), China (Qingdao), China (Beijing), China (Zhangjiakou), China (Shenzhen), China (Guangzhou), China (Chengdu), China (Hong Kong), Singapura, Indonésia (Jacarta) ou Alemanha (Frankfurt)
Faça login no OSS console.
No painel de navegação à esquerda, clique em Buckets. Na página exibida, clique no nome do bucket desejado.
No painel de navegação à esquerda, escolha .
Na página Data Indexing, se for o primeiro acesso, siga as instruções para conceder permissões ao AliyunMetaQueryDefaultRole e permitir que o OSS gerencie dados no bucket. Em seguida, clique em Enable Data Indexing.
-
Selecione MetaSearch e clique em Enable.
NotaA ativação do MetaSearch leva tempo, dependendo do número de objetos no bucket.
Para buckets na região Reino Unido (Londres), China (Ulanqab), EUA (Virgínia) ou EUA (Vale do Silício)
Faça login no OSS console.
No painel de navegação à esquerda, clique em Buckets. Na página exibida, clique no nome do bucket desejado.
No painel de navegação à esquerda, escolha . Se for o primeiro acesso, siga as instruções para conceder permissões ao AliyunMetaQueryDefaultRole e permitir que o OSS gerencie dados no bucket.
-
Ative a opção Metadata Management.
NotaA ativação do Metadata Management leva tempo, dependendo do número de objetos no bucket.
Alibaba Cloud SDK
Ative o MetaSearch para um bucket antes de executar consultas. Exemplo:
Java
import com.aliyun.oss.*;
import com.aliyun.oss.common.auth.*;
import com.aliyun.oss.common.comm.SignVersion;
import com.aliyun.oss.model.MetaQueryMode;
public class OpenMetaQuery {
public static void main(String[] args) throws com.aliyuncs.exceptions.ClientException {
// In this example, the endpoint of the China (Hangzhou) region is used.
String endpoint = "https://oss-cn-hangzhou.aliyuncs.com";
// Specify the name of the bucket. Example: examplebucket.
String bucketName = "examplebucket";
// Obtain access credentials from environment variables.
// Before you run the sample code, make sure that the OSS_ACCESS_KEY_ID and OSS_ACCESS_KEY_SECRET environment variables are configured.
EnvironmentVariableCredentialsProvider credentialsProvider = CredentialsProviderFactory.newEnvironmentVariableCredentialsProvider();
// Specify the region in which the bucket is located. For example, if the bucket is located in the China (Hangzhou) region, set the region to cn-hangzhou.
String region = "cn-hangzhou";
// Create an OSSClient instance.
//Call the shutdown method to release associated resources when the OSSClient instance is no longer used.
ClientBuilderConfiguration clientBuilderConfiguration = new ClientBuilderConfiguration();
clientBuilderConfiguration.setSignatureVersion(SignVersion.V4);
OSS ossClient = OSSClientBuilder.create()
.endpoint(endpoint)
.credentialsProvider(credentialsProvider)
.clientConfiguration(clientBuilderConfiguration)
.region(region)
.build();
try {
// Enable the MetaSearch feature.
ossClient.openMetaQuery(bucketName);
} catch (OSSException oe) {
System.out.println("Error Message:" + oe.getErrorMessage());
System.out.println("Error Code:" + oe.getErrorCode());
System.out.println("Request ID:" + oe.getRequestId());
System.out.println("Host ID:" + oe.getHostId());
} catch (ClientException ce) {
System.out.println("Error Message: " + ce.getMessage());
} finally {
// Shut down the OSSClient instance.
if(ossClient != null){
ossClient.shutdown();
}
}
}
}
Python
import argparse
import alibabacloud_oss_v2 as oss
# Create a command-line parameter parser and describe the purpose of the script.
parser = argparse.ArgumentParser(description="open meta query sample")
# Specify the --region parameter to indicate the region in which the bucket is located. This parameter is required.
parser.add_argument('--region', help='The region in which the bucket is located.', required=True)
# Specify the --bucket parameter to indicate the bucket. This parameter is required.
parser.add_argument('--bucket', help='The name of the bucket.', required=True)
# Specify the --endpoint parameter to indicate the endpoint for accessing OSS. This parameter is required.
parser.add_argument('--endpoint', help='The domain names that other services can use to access OSS')
def main():
# Parse the command-line arguments.
args = parser.parse_args()
# From the environment variables, load the authentication information required to access OSS.
credentials_provider = oss.credentials.EnvironmentVariableCredentialsProvider()
# Use the default configuration of the SDK.
cfg = oss.config.load_default()
# Specify the credential provider.
cfg.credentials_provider = credentials_provider
# Set the region to the one provided from the command line.
cfg.region = args.region
# If a custom endpoint is provided, update the endpoint attribute of the cfg object with the provided endpoint.
if args.endpoint is not None:
cfg.endpoint = args.endpoint
# Create an OSS client.
client = oss.Client(cfg)
# Initiate a request to enable metadata-based query.
result = client.open_meta_query(oss.OpenMetaQueryRequest(
bucket=args.bucket,
))
# Display the HTTP status code and request ID.
print(f'status code: {result.status_code},'
f' request id: {result.request_id},'
)
# Call the main function when the script is directly run.
if __name__ == "__main__":
main()
Go
package main
import (
"context"
"flag"
"log"
"github.com/aliyun/alibabacloud-oss-go-sdk-v2/oss"
"github.com/aliyun/alibabacloud-oss-go-sdk-v2/oss/credentials"
)
var (
region string // Specify a variable to store the region information obtained from the command lines.
bucketName string // Specify a variable to store the bucket name obtained from the command lines.
)
// The init function is executed before the main function to initialize the program.
func init() {
// Use a command line parameter to specify the region.
flag.StringVar(®ion, "region", "", "The region in which the bucket is located.")
// Use a command line parameter to specify the bucket name.
flag.StringVar(&bucketName, "bucket", "", "The name of the bucket.")
}
func main() {
flag.Parse() // Parse command line parameters.
// Check if the bucket name is specified. If not, the program outputs default parameters and terminates.
if len(bucketName) == 0 {
flag.PrintDefaults()
log.Fatalf("invalid parameters, bucket name required") // Log the error message and terminate the program.
}
// Check whether the region is specified. If the region is not specified, output the default parameters and exit the program.
if len(region) == 0 {
flag.PrintDefaults()
log.Fatalf("invalid parameters, region required") // Log the error message and terminate the program.
}
// Create and configure a client and use environment variables to pass the credential provider.
cfg := oss.LoadDefaultConfig().
WithCredentialsProvider(credentials.NewEnvironmentVariableCredentialsProvider()).
WithRegion(region)
client := oss.NewClient(cfg) // Use the client configurations to create a new OSSClient instance.
// Create an OpenMetaQuery request to enable the metadata management feature for a specific bucket.
request := &oss.OpenMetaQueryRequest{
Bucket: oss.Ptr(bucketName), // Specify the name of the bucket.
}
result, err := client.OpenMetaQuery(context.TODO(), request) // Execute the request to enable the metadata management feature for the bucket.
if err != nil {
log.Fatalf("failed to open meta query %v", err) // If an error occurs, record the error message and terminate the program.
}
log.Printf("open meta query result:%#v\n", result) // Display the result.
}
PHP
<?php // Import the autoloader file to ensure that dependency libraries can be correctly loaded. require_once __DIR__ . '/../vendor/autoload.php'; use AlibabaCloud\Oss\V2 as Oss; // Define the description of command line arguments. $optsdesc = [ "region" => ['help' => 'The region in which the bucket is located.', 'required' => True], // The region in which the bucket is located. This parameter is required. "endpoint" => ['help' => 'The domain names that other services can use to access OSS.', 'required' => False], // The endpoint that other services can use to access OSS. This parameter is optional. "bucket" => ['help' => 'The name of the bucket', 'required' => True], // The name of the bucket. This parameter is required. ]; // Convert the argument description to the long option format required by getopt. // A colon (:) after each argument indicates that the argument requires a value. $longopts = \array_map(function ($key) { return "$key:"; }, array_keys($optsdesc)); // Parse the command line arguments. $options = getopt("", $longopts); // Check whether the required arguments are specified. foreach ($optsdesc as $key => $value) { if ($value['required'] === True && empty($options[$key])) { $help = $value['help']; // Obtain the help information of the argument. echo "Error: the following arguments are required: --$key, $help" . PHP_EOL; exit(1); // If a required argument is not specified, exit the program. } } // Extract values from the parsed arguments. $region = $options["region"]; // The region in which the bucket is located. $bucket = $options["bucket"]; // The name of the bucket. // Load the credential information from environment variables. // Use EnvironmentVariableCredentialsProvider to read the Access Key ID and Access Key Secret from environment variables. $credentialsProvider = new Oss\Credentials\EnvironmentVariableCredentialsProvider(); // Use the default configurations of the SDK. $cfg = Oss\Config::loadDefault(); $cfg->setCredentialsProvider($credentialsProvider); // Set the credential provider. $cfg->setRegion($region); // Set the region in which the bucket is located. if (isset($options["endpoint"])) { $cfg->setEndpoint($options["endpoint"]); // If an endpoint is provided, set the endpoint. } // Create an OSS client instance. $client = new Oss\Client($cfg); // Create an OpenMetaQueryRequest object to enable the scalar retrieval feature for the bucket. $request = new Oss\Models\OpenMetaQueryRequest( bucket: $bucket ); // Execute the operation to enable the scalar retrieval feature. $result = $client->openMetaQuery($request); // Print the result of enabling the scalar retrieval feature. printf( 'status code:' . $result->statusCode . PHP_EOL . // The HTTP status code. For example, 200 indicates that the request is successful. 'request id:' . $result->requestId . PHP_EOL // The request ID, which is used to debug or track requests. );
Ossutil
Ative o MetaSearch para um bucket chamado examplebucket:
ossutil api open-meta-query --bucket examplebucket
Executar uma consulta MetaSearch
OSS console
Este exemplo localiza objetos menores que 500 KB, modificados pela última vez entre 00:00 de 11 de setembro de 2024 e 00:00 de 12 de setembro de 2024, ordenados por tamanho do objeto em ordem crescente, com agregação pelo tamanho máximo do objeto.
Faça login no OSS console.
No painel de navegação à esquerda, clique em Buckets. Na página exibida, clique no nome do bucket desejado.
No painel de navegação à esquerda, escolha .
-
Configure os parâmetros abaixo. Mantenha os demais com os valores padrão.
Defina Last Modified At para o intervalo de 00:00 de 11 de setembro de 2024 até 00:00 de 12 de setembro de 2024.
Defina Object Size como menor que 500 KB.
-
Expanda a seção More filter conditions.
Em Object Sort Order, selecione Object Size e Ascending.
Em Data Aggregation, selecione Maximum para Object Size.

-
Condições de consulta e configurações de saída.
Clique em Query. Dois objetos correspondem às condições da consulta. O maior objeto tem 434 KB.

Alibaba Cloud SDK
Estes exemplos consultam objetos que correspondem a condições especificadas.
Java
Exemplos adicionais: MetaSearch (Java SDK V1).
import com.aliyun.oss.*;
import com.aliyun.oss.common.auth.*;
import com.aliyun.oss.common.comm.SignVersion;
import com.aliyun.oss.model.*;
import java.util.ArrayList;
import java.util.List;
public class DoMetaQuery {
public static void main(String[] args) throws Exception {
// In this example, the endpoint of the China (Hangzhou) region is used.
String endpoint = "https://oss-cn-hangzhou.aliyuncs.com";
// Specify the name of the bucket. Example: examplebucket.
String bucketName = "examplebucket";
// Obtain access credentials from environment variables.
// Before you run the sample code, make sure that the OSS_ACCESS_KEY_ID and OSS_ACCESS_KEY_SECRET environment variables are configured.
EnvironmentVariableCredentialsProvider credentialsProvider = CredentialsProviderFactory.newEnvironmentVariableCredentialsProvider();
// Specify the region in which the bucket is located. For example, if the bucket is located in the China (Hangzhou) region, set the region to cn-hangzhou.
String region = "cn-hangzhou";
// Create an OSSClient instance.
// Call the shutdown method to release associated resources when the OSSClient instance is no longer used.
ClientBuilderConfiguration clientBuilderConfiguration = new ClientBuilderConfiguration();
clientBuilderConfiguration.setSignatureVersion(SignVersion.V4);
OSS ossClient = OSSClientBuilder.create()
.endpoint(endpoint)
.credentialsProvider(credentialsProvider)
.clientConfiguration(clientBuilderConfiguration)
.region(region)
.build();
try {
// Query objects that meet specific conditions and return objects based on specific fields and in the specified sorting order.
int maxResults = 20;
// Query objects that are smaller than 1,048,576 bytes in size, return up to 20 objects at a time, and sort the objects in ascending order.
String query = "{\"Field\": \"Size\",\"Value\": \"1048576\",\"Operation\": \"lt\"}";
String sort = "Size";
DoMetaQueryRequest doMetaQueryRequest = new DoMetaQueryRequest(bucketName, maxResults, query, sort);
Aggregation aggregationRequest = new Aggregation();
Aggregations aggregations = new Aggregations();
List<Aggregation> aggregationList = new ArrayList<Aggregation>();
// Specify the name of the field that is used in the aggregate operation.
aggregationRequest.setField("Size");
// Specify the operator that is used in the aggregate operation. max indicates the maximum value.
aggregationRequest.setOperation("max");
aggregationList.add(aggregationRequest);
aggregations.setAggregation(aggregationList);
// Specify the aggregate operation.
doMetaQueryRequest.setAggregations(aggregations);
doMetaQueryRequest.setOrder(SortOrder.ASC);
DoMetaQueryResult doMetaQueryResult = ossClient.doMetaQuery(doMetaQueryRequest);
if(doMetaQueryResult.getFiles() != null){
for(ObjectFile file : doMetaQueryResult.getFiles().getFile()){
System.out.println("Filename: " + file.getFilename());
// Query the ETag value that is used to identify the content of the object.
System.out.println("ETag: " + file.getETag());
// Query the access control list (ACL) of the object.
System.out.println("ObjectACL: " + file.getObjectACL());
// Query the type of the object.
System.out.println("OssObjectType: " + file.getOssObjectType());
// Query the storage class of the object.
System.out.println("OssStorageClass: " + file.getOssStorageClass());
// Query the number of tags of the object.
System.out.println("TaggingCount: " + file.getOssTaggingCount());
if(file.getOssTagging() != null){
for(Tagging tag : file.getOssTagging().getTagging()){
System.out.println("Key: " + tag.getKey());
System.out.println("Value: " + tag.getValue());
}
}
if(file.getOssUserMeta() != null){
for(UserMeta meta : file.getOssUserMeta().getUserMeta()){
System.out.println("Key: " + meta.getKey());
System.out.println("Value: " + meta.getValue());
}
}
}
} else if(doMetaQueryResult.getAggregations() != null){
for(Aggregation aggre : doMetaQueryResult.getAggregations().getAggregation()){
// Query the field by which the aggregation is performed.
System.out.println("Field: " + aggre.getField());
// Query the aggregation operator.
System.out.println("Operation: " + aggre.getOperation());
// Query the result of the aggregate operation.
System.out.println("Value: " + aggre.getValue());
if(aggre.getGroups() != null && aggre.getGroups().getGroup().size() > 0){
// Query the value of the aggregation.
System.out.println("Groups value: " + aggre.getGroups().getGroup().get(0).getValue());
// Query the total number of the aggregations.
System.out.println("Groups count: " + aggre.getGroups().getGroup().get(0).getCount());
}
}
} else {
System.out.println("NextToken: " + doMetaQueryResult.getNextToken());
}
} catch (OSSException oe) {
System.out.println("Error Message:" + oe.getErrorMessage());
System.out.println("Error Code:" + oe.getErrorCode());
System.out.println("Request ID:" + oe.getRequestId());
System.out.println("Host ID:" + oe.getHostId());
} catch (ClientException ce) {
System.out.println("Error Message: " + ce.getMessage());
} finally {
// Shut down the OSSClient instance.
ossClient.shutdown();
}
}
}
Python
Exemplos adicionais: MetaSearch.
import argparse
import alibabacloud_oss_v2 as oss
# Create a command-line parameter parser for parsing arguments from the command line.
parser = argparse.ArgumentParser(description="do meta query sample")
parser.add_argument('--region', help='The region in which the bucket is located.', required=True)
parser.add_argument('--bucket', help='The name of the bucket.', required=True)
parser.add_argument('--endpoint', help='The domain names that other services can use to access OSS')
def main():
# Parse the command-line arguments.
args = parser.parse_args()
# Obtain access credentials from environment variables.
credentials_provider = oss.credentials.EnvironmentVariableCredentialsProvider()
# Use the default configuration of the SDK.
cfg = oss.config.load_default()
# Specify the credential provider.
cfg.credentials_provider = credentials_provider
# Set the region to the one provided from the command line.
cfg.region = args.region
# If a custom endpoint is provided, update the endpoint attribute of the cfg object with the provided endpoint.
if args.endpoint is not None:
cfg.endpoint = args.endpoint
# Create an OSS client.
client = oss.Client(cfg)
# Perform the metadata-based query.
result = client.do_meta_query(oss.DoMetaQueryRequest(
bucket=args.bucket, # The bucket that stores the objects to be queried.
meta_query=oss.MetaQuery( # Specify query settings.
aggregations=oss.MetaQueryAggregations( # Specify aggregatios.
aggregations=[ # The aggregation list.
oss.MetaQueryAggregation( # The first aggregation: the total object size.
field='Size',
operation='sum',
),
oss.MetaQueryAggregation( # The second aggregation: the maximum object size.
field='Size',
operation='max',
)
],
),
next_token='', # The pagination token.
max_results=80369, # The maximum number of entries that can be returned.
query='{"Field": "Size","Value": "1048576","Operation": "gt"}', # The query condition.
sort='Size', # The sorting field.
order=oss.MetaQueryOrderType.DESC, # The sorting order.
),
))
# Display the basic response information.
print(f'status code: {result.status_code},'
f' request id: {result.request_id},'
# You can uncomment the one or more of the following lines to display more details.
# f' files: {result.files},'
# f' file: {result.files.file},'
# f' file modified time: {result.files.file.file_modified_time},'
# f' etag: {result.files.file.etag},'
# f' server side encryption: {result.files.file.server_side_encryption},'
# f' oss tagging count: {result.files.file.oss_tagging_count},'
# f' oss tagging: {result.files.file.oss_tagging},'
# f' key: {result.files.file.oss_tagging.taggings[0].key},'
# f' value: {result.files.file.oss_tagging.taggings[0].value},'
# f' key: {result.files.file.oss_tagging.taggings[1].key},'
# f' value: {result.files.file.oss_tagging.taggings[1].value},'
# f' oss user meta: {result.files.file.oss_user_meta},'
# f' key: {result.files.file.oss_user_meta.user_metas[0].key},'
# f' value: {result.files.file.oss_user_meta.user_metas[0].value},'
# f' key: {result.files.file.oss_user_meta.user_metas[1].key},'
# f' value: {result.files.file.oss_user_meta.user_metas[1].value},'
# f' filename: {result.files.file.filename},'
# f' size: {result.files.file.size},'
# f' oss object type: {result.files.file.oss_object_type},'
# f' oss storage class: {result.files.file.oss_storage_class},'
# f' object acl: {result.files.file.object_acl},'
# f' oss crc64: {result.files.file.oss_crc64},'
# f' server side encryption customer algorithm: {result.files.file.server_side_encryption_customer_algorithm},'
# f' aggregations: {result.aggregations},'
f' field: {result.aggregations.aggregations[0].field},'
f' operation: {result.aggregations.aggregations[0].operation},'
f' field: {result.aggregations.aggregations[1].field},'
f' operation: {result.aggregations.aggregations[1].operation},'
f' next token: {result.next_token},'
)
# If matched objects are found, display tags and user metadata.
if result.files:
if result.files.file.oss_tagging.taggings:
for r in result.files.file.oss_tagging.taggings:
print(f'result: key: {r.key}, value: {r.value}')
if result.files.file.oss_user_meta.user_metas:
for r in result.files.file.oss_user_meta.user_metas:
print(f'result: key: {r.key}, value: {r.value}')
# Display all aggregations.
if result.aggregations.aggregations:
for r in result.aggregations.aggregations:
print(f'result: field: {r.field}, operation: {r.operation}')
if __name__ == "__main__":
main()
Go
Exemplos adicionais: MetaSearch (Go SDK V2).
package main import ( "context" "flag" "fmt" "log" "github.com/aliyun/alibabacloud-oss-go-sdk-v2/oss" "github.com/aliyun/alibabacloud-oss-go-sdk-v2/oss/credentials" ) var ( region string // Specify a variable to store the region information obtained from the command lines. bucketName string // Specify a variable to store the bucket name obtained from the command lines. ) // The init function is executed before the main function to initialize the program. func init() { // Use a command line parameter to specify the region. By default, the parameter is an empty string. flag.StringVar(®ion, "region", "", "The region in which the bucket is located.") // Use a command line parameter to specify the bucket name. By default, the parameter is an empty string. flag.StringVar(&bucketName, "bucket", "", "The name of the bucket.") } func main() { flag.Parse() // Parse command line parameters. // Check if the bucket name is specified. If not, the program outputs default parameters and terminates. if len(bucketName) == 0 { flag.PrintDefaults() log.Fatalf("invalid parameters, bucket name required") } // Check if the region is specified. If not, the program outputs default parameters and terminates. if len(region) == 0 { flag.PrintDefaults() log.Fatalf("invalid parameters, region required") } // Create and configure a client and use environment variables to pass the credential provider and the region. cfg := oss.LoadDefaultConfig(). WithCredentialsProvider(credentials.NewEnvironmentVariableCredentialsProvider()). WithRegion(region) client := oss.NewClient(cfg) // Use the client configurations to create a new OSSClient instance. // Create a DoMetaQuery request to query the objects that meet specific conditions. request := &oss.DoMetaQueryRequest{ Bucket: oss.Ptr(bucketName), // Specify the name of the bucket. MetaQuery: &oss.MetaQuery{ Query: oss.Ptr({"Field": "Size","Value": "1048576","Operation": "gt"}), // Query objects whose size is larger than 1 MB. Sort: oss.Ptr("Size"), // List the objects by size. Order: oss.Ptr(oss.MetaQueryOrderAsc), // Sort the objects in ascending order. }, } result, err := client.DoMetaQuery(context.TODO(), request) // Execute the request to query the objects that meet the preceding conditions. if err != nil { log.Fatalf("failed to do meta query %v", err) } // Display the token used to query data on the next page. fmt.Printf("NextToken:%s\n", result.NextToken) // Traverse the returned results and display the details of each object. for _, file := range result.Files { fmt.Printf("File name: %s\n", file.Filename) fmt.Printf("size: %d\n", file.Size) fmt.Printf("File Modified Time:%s\n", file.FileModifiedTime) fmt.Printf("Oss Object Type:%s\n", file.OSSObjectType) fmt.Printf("Oss Storage Class:%s\n", file.OSSStorageClass) fmt.Printf("Object ACL:%s\n", file.ObjectACL) fmt.Printf("ETag:%s\n", file.ETag) fmt.Printf("Oss CRC64:%s\n", file.OSSCRC64) if file.OSSTaggingCount != nil { fmt.Printf("Oss Tagging Count:%d\n", file.OSSTaggingCount) } // Display the tags of the objects. for _, tagging := range file.OSSTagging { fmt.Printf("Oss Tagging Key:%s\n", tagging.Key) fmt.Printf("Oss Tagging Value:%s\n", tagging.Value) } // Display the user metadata. for _, userMeta := range file.OSSUserMeta { fmt.Printf("Oss User Meta Key:%s\n", userMeta.Key) fmt.Printf("Oss User Meta Key Value:%s\n", *userMeta.Value) } } }
PHP
Exemplos adicionais: MetaSearch (PHP SDK V2).
<?php // Import the autoloader file to ensure that dependency libraries can be correctly loaded. require_once __DIR__ . '/../vendor/autoload.php'; use AlibabaCloud\Oss\V2 as Oss; // Define the description of command line arguments. $optsdesc = [ "region" => ['help' => 'The region in which the bucket is located.', 'required' => True], // The region in which the bucket is located. This parameter is required. "endpoint" => ['help' => 'The domain names that other services can use to access OSS.', 'required' => False], // The endpoint that other services can use to access OSS. This parameter is optional. "bucket" => ['help' => 'The name of the bucket', 'required' => True], // The name of the bucket. This parameter is required. ]; // Convert the argument description to the long option format required by getopt. // A colon (:) after each argument indicates that the argument requires a value. $longopts = \array_map(function ($key) { return "$key:"; }, array_keys($optsdesc)); // Parse the command line arguments. $options = getopt("", $longopts); // Check whether the required arguments are specified. foreach ($optsdesc as $key => $value) { if ($value['required'] === True && empty($options[$key])) { $help = $value['help']; // Obtain the help information of the argument. echo "Error: the following arguments are required: --$key, $help" . PHP_EOL; exit(1); // If a required argument is not specified, exit the program. } } // Extract values from the parsed arguments. $region = $options["region"]; // The region in which the bucket is located. $bucket = $options["bucket"]; // The name of the bucket. // Load the credential information from environment variables. // Use EnvironmentVariableCredentialsProvider to read the Access Key ID and Access Key Secret from environment variables. $credentialsProvider = new Oss\Credentials\EnvironmentVariableCredentialsProvider(); // Use the default configurations of the SDK. $cfg = Oss\Config::loadDefault(); $cfg->setCredentialsProvider($credentialsProvider); // Set the credential provider. $cfg->setRegion($region); // Set the region in which the bucket is located. if (isset($options["endpoint"])) { $cfg->setEndpoint($options["endpoint"]); // If an endpoint is provided, set the endpoint. } // Create an OSS client instance. $client = new Oss\Client($cfg); // Create a DoMetaQueryRequest object to perform a metadata query operation. $request = new \AlibabaCloud\Oss\V2\Models\DoMetaQueryRequest( bucket: $bucket, metaQuery: new \AlibabaCloud\Oss\V2\Models\MetaQuery( maxResults: 5, // The maximum number of results to return. query: "{'Field': 'Size','Value': '1048576','Operation': 'gt'}", // Query condition: objects whose size is greater than 1 MB. sort: 'Size', // Sort by object size. order: \AlibabaCloud\Oss\V2\Models\MetaQueryOrderType::ASC, // Sort in ascending order. aggregations: new \AlibabaCloud\Oss\V2\Models\MetaQueryAggregations( // Aggregate operation aggregations: [ new \AlibabaCloud\Oss\V2\Models\MetaQueryAggregation( field: 'Size', // The object size field. operation: 'sum' // Aggregate operation: sum. ), new \AlibabaCloud\Oss\V2\Models\MetaQueryAggregation( field: 'Size', // The object size field. operation: 'max' // Aggregate operation: maximum value. ), ] ) ) ); // Perform the metadata query operation. $result = $client->doMetaQuery($request); // Print the result of the metadata query. printf( 'status code:' . $result->statusCode . PHP_EOL . // The HTTP status code. For example, 200 indicates that the request is successful. 'request id:' . $result->requestId . PHP_EOL . // The request ID, which is used to debug or track requests. 'result:' . var_export($result, true) . PHP_EOL // The query result, which contains the matched objects and their aggregate data. );
Usar ossutil
Utilize o ossutil para consultar objetos correspondentes. Para instalar o ossutil, consulte Instalar ossutil.
Consulte objetos correspondentes no bucket examplebucket:
ossutil api do-meta-query --bucket examplebucket --meta-query "{\"MaxResults\":\"5\",\"Query\":\"{\\\"Field\\\": \\\"Size\\\",\\\"Value\\\": \\\"1048576\\\",\\\"Operation\\\": \\\"gt\\\"}\",\"Sort\":\"Size\",\"Order\":\"asc\",\"Aggregations\":{\"Aggregation\":[{\"Field\":\"Size\",\"Operation\":\"sum\"},{\"Field\":\"Size\",\"Operation\":\"max\"}]}}"
Desativar o MetaSearch
Desativar o MetaSearch não afeta os dados armazenados. Reativar o recurso faz com que os arquivos existentes sejam verificados novamente e o índice seja reconstruído. O tempo necessário depende do número de arquivos no bucket.
A cobrança cessa na hora seguinte à desativação do recurso. A geração da fatura pode sofrer atrasos; monitore suas faturas para garantir a precisão.
OSS console
Faça login no OSS console. Na página Data Indexing, clique em Disable ao lado de Metadata Management e siga as instruções.

Alibaba Cloud SDK
Java
Exemplos adicionais: MetaSearch (OSS SDK for Java V1).
import com.aliyun.oss.; import com.aliyun.oss.common.auth.; import com.aliyun.oss.common.comm.SignVersion; public class CloseMetaQuery { public static void main(String[] args) throws Exception { // In this example, the endpoint of the China (Hangzhou) region is used. String endpoint = "https://oss-cn-hangzhou.aliyuncs.com"; // Specify the name of the bucket. Example: examplebucket. String bucketName = "examplebucket"; // Obtain access credentials from environment variables. // Before you run the sample code, make sure that the OSS_ACCESS_KEY_ID and OSS_ACCESS_KEY_SECRET environment variables are configured. EnvironmentVariableCredentialsProvider credentialsProvider = CredentialsProviderFactory.newEnvironmentVariableCredentialsProvider(); // Specify the region in which the bucket is located. For example, if the bucket is located in the China (Hangzhou) region, set the region to cn-hangzhou. String region = "cn-hangzhou"; // Create an OSSClient instance. // Call the shutdown method to release associated resources when the OSSClient instance is no longer used. ClientBuilderConfiguration clientBuilderConfiguration = new ClientBuilderConfiguration(); clientBuilderConfiguration.setSignatureVersion(SignVersion.V4); OSS ossClient = OSSClientBuilder.create() .endpoint(endpoint) .credentialsProvider(credentialsProvider) .clientConfiguration(clientBuilderConfiguration) .region(region) .build(); try { // Disable the MetaSearch feature for the bucket. ossClient.closeMetaQuery(bucketName); } catch (OSSException oe) { System.out.println("Error Message:" + oe.getErrorMessage()); System.out.println("Error Code:" + oe.getErrorCode()); System.out.println("Request ID:" + oe.getRequestId()); System.out.println("Host ID:" + oe.getHostId()); } catch (ClientException ce) { System.out.println("Error Message: " + ce.getMessage()); } finally { // Shut down the OSSClient instance. if(ossClient != null){ ossClient.shutdown(); } } } }
Python
Exemplos adicionais: MetaSearch.
import argparse import alibabacloud_oss_v2 as oss # Create an ArgumentParser object for processing command-line arguments. parser = argparse.ArgumentParser(description="close meta query sample") parser.add_argument('--region', help='The region in which the bucket is located.', required=True) parser.add_argument('--bucket', help='The name of the bucket.', required=True) parser.add_argument('--endpoint', help='The domain names that other services can use to access OSS') def main(): # Parse the command-line arguments. args = parser.parse_args() # Obtain access credentials from environment variables. credentials_provider = oss.credentials.EnvironmentVariableCredentialsProvider() # Use the default configuration of the SDK. cfg = oss.config.load_default() # Set the credential provider to the credential provider obtained from the environment variables. cfg.credentials_provider = credentials_provider # Set the region in the configuration to the one specified in the command line. cfg.region = args.region # If a custom endpoint is provided, update the endpoint attribute of the cfg object with the provided endpoint. if args.endpoint is not None: cfg.endpoint = args.endpoint # Create an OSS client. client = oss.Client(cfg) # Call the close_meta_query method to disable the metadata query feature for the specified bucket. result = client.close_meta_query(oss.CloseMetaQueryRequest( bucket=args.bucket, )) # Display the HTTP status code and request ID. print(f'status code: {result.status_code}, request id: {result.request_id}') # Call the main function when the script is directly run. if __name__ == "__main__": main()
Go
Exemplos adicionais: MetaSearch (OSS SDK for Go V2).
package main import ( "context" "flag" "log" "github.com/aliyun/alibabacloud-oss-go-sdk-v2/oss" "github.com/aliyun/alibabacloud-oss-go-sdk-v2/oss/credentials" ) var ( region string // Specify a variable to store the region information obtained from the command lines. bucketName string // Specify a variable to store the bucket name obtained from the command lines. ) // The init function is executed before the main function to initialize the program. func init() { // Use a command line parameter to specify the region. flag.StringVar(®ion, "region", "", "The region in which the bucket is located.") // Use a command line parameter to specify the bucket name. flag.StringVar(&bucketName, "bucket", "", "The name of the bucket.") } func main() { flag.Parse() // Parse command line parameters. // Check if the bucket name is specified. If not, the program outputs default parameters and terminates. if len(bucketName) == 0 { flag.PrintDefaults() log.Fatalf("invalid parameters, bucket name required") // Log the error message and terminate the program. } // Check if the region is specified. If not, the program outputs default parameters and terminates. if len(region) == 0 { flag.PrintDefaults() log.Fatalf("invalid parameters, region required") // Log the error message and terminate the program. } // Create and configure a client and use environment variables to pass the credential provider and the region. cfg := oss.LoadDefaultConfig(). WithCredentialsProvider(credentials.NewEnvironmentVariableCredentialsProvider()). WithRegion(region) client := oss.NewClient(cfg) // Create a new OSSClient instance. // Create a CloseMetaQuery request to disable the metadata management feature for the bucket. request := &oss.CloseMetaQueryRequest{ Bucket: oss.Ptr(bucketName), // Specify the name of the bucket. } result, err := client.CloseMetaQuery(context.TODO(), request) // Execute the request. if err != nil { log.Fatalf("failed to close meta query %v", err) // If an error occurs, record the error message and exit the program. } log.Printf("close meta query result:%#v\n", result) }
PHP
Exemplos adicionais: MetaSearch (OSS SDK for PHP V2).
<?php // Import the autoloader file to ensure that dependency libraries can be correctly loaded. require_once __DIR__ . '/../vendor/autoload.php'; use AlibabaCloud\Oss\V2 as Oss; // Define the description of command line arguments. $optsdesc = [ "region" => ['help' => 'The region in which the bucket is located.', 'required' => True], // The region in which the bucket is located. This parameter is required. "endpoint" => ['help' => 'The domain names that other services can use to access OSS.', 'required' => False], // The endpoint that other services can use to access OSS. This parameter is optional. "bucket" => ['help' => 'The name of the bucket', 'required' => True], // The name of the bucket. This parameter is required. ]; // Convert the argument description to the long option format required by getopt. // A colon (:) after each argument indicates that the argument requires a value. $longopts = \array_map(function ($key) { return "$key:"; }, array_keys($optsdesc)); // Parse the command line arguments. $options = getopt("", $longopts); // Check whether the required arguments are specified. foreach ($optsdesc as $key => $value) { if ($value['required'] === True && empty($options[$key])) { $help = $value['help']; // Obtain the help information of the argument. echo "Error: the following arguments are required: --$key, $help" . PHP_EOL; exit(1); // If a required argument is not specified, exit the program. } } // Extract values from the parsed arguments. $region = $options["region"]; // The region in which the bucket is located. $bucket = $options["bucket"]; // The name of the bucket. // Load the credential information from environment variables. // Use EnvironmentVariableCredentialsProvider to read the Access Key ID and Access Key Secret from environment variables. $credentialsProvider = new Oss\Credentials\EnvironmentVariableCredentialsProvider(); // Use the default configurations of the SDK. $cfg = Oss\Config::loadDefault(); $cfg->setCredentialsProvider($credentialsProvider); // Set the credential provider. $cfg->setRegion($region); // Set the region in which the bucket is located. if (isset($options["endpoint"])) { $cfg->setEndpoint($options["endpoint"]); // If an endpoint is provided, set the endpoint. } // Create an OSS client instance. $client = new Oss\Client($cfg); // Create a CloseMetaQueryRequest object to disable the retrieval feature for the bucket. $request = new \AlibabaCloud\Oss\V2\Models\CloseMetaQueryRequest( bucket: $bucket ); // Execute the operation to disable the retrieval feature. $result = $client->closeMetaQuery($request); // Print the result of disabling the retrieval feature. printf( 'status code:' . $result->statusCode . PHP_EOL . // The HTTP status code. For example, 200 indicates that the request is successful. 'request id:' . $result->requestId . PHP_EOL // The request ID, which is used to debug or track requests. );
ossutil
Este exemplo desativa o MetaSearch para o bucket examplebucket:
ossutil api close-meta-query --bucket examplebucket
Condições de consulta e configurações de saída
Condições de consulta
Utilize estas condições individualmente ou combinadas.
Configurações de saída
Ordene os resultados e agregue estatísticas.
Object Sort Order: Ordene por hora da última modificação, nome do objeto ou tamanho do objeto em ordem crescente, decrescente ou padrão.
Data Aggregation: Realize cálculos nos resultados da consulta, como contagem de itens únicos, agrupamento e contagem, busca de valores máximos ou mínimos, cálculo de médias e soma de valores.
APIs relacionadas
Para maior personalização, chame as APIs REST diretamente. Você deve calcular a assinatura manualmente.
Ative o gerenciamento de metadados com OpenMetaQuery.
Consulte arquivos correspondentes com DoMetaQuery.
Desative o gerenciamento de metadados com CloseMetaQuery.
Faturamento
-
Os preços do MetaSearch consistem nos dois componentes a seguir:
-
Taxas do recurso MetaSearch
São taxas de gerenciamento de metadados de objetos, cobradas à taxa padrão para indexação de dados do OSS. Consulte Taxas de indexação de dados.
-
Taxas de solicitação de API
As taxas de solicitação de API são incorridas durante atualizações incrementais do índice de arquivos. A cobrança é baseada no número de chamadas de API. A tabela a seguir lista as solicitações de API que geram essas taxas:
Ações
API
Contagem
Indexar um objeto em um bucket
HeadObject e GetObject
Chamada uma vez por objeto
Indexar um objeto que possui tags
GetObjectTag
Chamada uma vez por objeto com tags
Indexar um objeto que possui metadados personalizados
GetObjectMeta
Chamada uma vez por objeto com metadados personalizados
Indexar um link simbólico
GetSymlink
Chamada uma vez por link simbólico
Verificar objetos em um bucket
ListObjects
Chamada uma vez para cada 1.000 objetos verificados
-
Para interromper essas cobranças, desative o MetaSearch.
Perguntas frequentes
Criação lenta de índice de dados para buckets grandes
O processo de indexação trata aproximadamente 600 objetos incrementais por segundo. Estime o tempo total com base na contagem de objetos do bucket.
Consultar o tamanho total de objetos por prefixo
Faça login no OSS console.
No painel de navegação à esquerda, clique em Buckets. Na página exibida, clique no nome do bucket desejado.
No painel de navegação à esquerda, escolha .
-
Defina Object Name como Prefix Match e insira o prefixo:
random_files/. Mantenha os outros parâmetros com as configurações padrão.
-
Configure as Search Result Settings.
Em Object Sort Order, selecione Default.
-
Em Data Aggregation, selecione Sum de Object Size.

-
Clique em Query Now. Os resultados mostram o tamanho total de todos os objetos com o prefixo
random_files/.
Documentação relacionada
O MetaSearch filtra por hora da última modificação, classe de armazenamento, ACL e tamanho do arquivo. Como filtrar arquivos no OSS dentro de um intervalo de tempo especificado.