MetaSearch indexe les métadonnées des objets dans OSS, ce qui vous permet de filtrer et de récupérer des objets selon des conditions personnalisées.
Cas d'utilisation
Audit des données
Localisez rapidement les fichiers lors d'audits de données ou pour assurer la conformité réglementaire. Par exemple, dans les services financiers, filtrez par tags personnalisés et autorisations d'accès afin de trouver les fichiers présentant des niveaux de sensibilité spécifiques.
Sauvegarde et archivage des données d'entreprise
Récupérez les fichiers par date ou par type lors des opérations de sauvegarde et d'archivage. Filtrez par heure de création, classe de stockage ou tags personnalisés pour localiser les enregistrements historiques ou archivés.
Limites
-
Limite régionale
MetaSearch est disponible dans les régions suivantes : Chine (Hangzhou), Chine (Shanghai), Chine (Qingdao), Chine (Pékin), Chine (Zhangjiakou), Chine (Shenzhen), Chine (Guangzhou), Chine (Chengdu), Chine (Ulanqab), Chine (Hong Kong), Singapour, Indonésie (Jakarta), Allemagne (Francfort), États-Unis (Virginie), États-Unis (Silicon Valley) et Royaume-Uni (Londres).
-
Limite du bucket
Un bucket avec MetaSearch activé peut contenir jusqu'à 50 milliards d'objets. Le dépassement de cette limite peut dégrader les performances de récupération. Pour traiter des volumes de données plus importants, contactez le support technique pour une évaluation.
-
Téléchargement multipartie
Pour les objets créés par téléchargement multipartie, les résultats de requête affichent uniquement les objets complets assemblés à l'aide de l'opération CompleteMultipartUpload, et non les parties de téléchargement incomplètes ou abandonnées.
Performances
Les métriques suivantes sont fournies à titre indicatif.
-
Temps de génération de l'index pour les fichiers existants
100 millions de fichiers dans un seul bucket : 4 heures
1 milliard de fichiers dans un seul bucket : environ 10 heures
10 milliards de fichiers dans un seul bucket : environ 1 à 3 jours
20 milliards de fichiers dans un seul bucket : environ 2 à 4 jours
30 milliards de fichiers dans un seul bucket : environ 3 à 6 jours
50 milliards de fichiers dans un seul bucket : environ 6 à 10 jours
Si votre bucket contient plus d'un milliard de fichiers avec des tags, la génération de l'index prendra plus de temps que les estimations ci-dessus.
-
Temps de mise à jour de l'index pour les fichiers incrémentiels
Par défaut, OSS alloue 5 000 QPS à MetaSearch pour les mises à jour d'index, indépendamment du QoS de votre bucket. Lorsque le taux d'ajout, de modification ou de suppression de fichiers reste inférieur à 5 000, les mises à jour deviennent généralement consultables en quelques minutes. Si le taux dépasse 5 000 QPS, contactez le support technique pour obtenir de l'aide.
-
Performances de récupération des fichiers
La récupération s'effectue en quelques secondes, avec un délai d'expiration par défaut de 30 secondes.
Activer MetaSearch
Console OSS
Pour les buckets situés en Chine (Hangzhou), Chine (Shanghai), Chine (Qingdao), Chine (Pékin), Chine (Zhangjiakou), Chine (Shenzhen), Chine (Guangzhou), Chine (Chengdu), Chine (Hong Kong), Singapour, Indonésie (Jakarta) ou Allemagne (Francfort)
Connectez-vous à la console OSS.
Dans le volet de navigation de gauche, cliquez sur Buckets. Sur la page qui s'affiche, cliquez sur le nom du bucket cible.
Dans le volet de navigation de gauche, choisissez .
Sur la page Data Indexing, si c'est la première fois, suivez les instructions pour accorder des autorisations à AliyunMetaQueryDefaultRole afin qu'OSS puisse gérer les données dans le bucket. Cliquez ensuite sur Enable Data Indexing.
-
Sélectionnez MetaSearch puis cliquez sur Enable.
RemarqueL'activation de MetaSearch prend un certain temps, qui dépend du nombre d'objets dans le bucket.
Pour les buckets situés dans la région Royaume-Uni (Londres), Chine (Ulanqab), États-Unis (Virginie) ou États-Unis (Silicon Valley)
Connectez-vous à la console OSS.
Dans le volet de navigation de gauche, cliquez sur Buckets. Sur la page qui s'affiche, cliquez sur le nom du bucket cible.
Dans le volet de navigation de gauche, choisissez . Si c'est la première fois, suivez les instructions pour accorder des autorisations à AliyunMetaQueryDefaultRole afin qu'OSS puisse gérer les données dans le bucket.
-
Activez Metadata Management.
RemarqueL'activation de Metadata Management prend un certain temps, qui dépend du nombre d'objets dans le bucket.
SDK Alibaba Cloud
Activez MetaSearch pour un bucket avant d'exécuter des requêtes. Exemple :
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
Activez MetaSearch pour un bucket nommé examplebucket :
ossutil api open-meta-query --bucket examplebucket
Exécuter une requête MetaSearch
Console OSS
Cet exemple recherche les objets dont la taille est inférieure à 500 Ko, modifiés pour la dernière fois entre le 11 septembre 2024 à 00:00 et le 12 septembre 2024 à 00:00. Les résultats sont triés par taille d'objet croissante et incluent une agrégation sur la taille maximale des objets.
Connectez-vous à la console OSS.
Dans le volet de navigation de gauche, cliquez sur Buckets. Sur la page qui s'affiche, cliquez sur le nom du bucket cible.
Dans le volet de navigation de gauche, choisissez .
-
Configurez les paramètres suivants. Laissez les autres paramètres avec leurs valeurs par défaut.
Définissez Last Modified At sur la plage allant du 11 septembre 2024 à 00:00 au 12 septembre 2024 à 00:00.
Définissez Object Size sur une valeur inférieure à 500 Ko.
-
Développez More filter conditions.
Pour Object Sort Order, sélectionnez Object Size et Ascending.
Pour Data Aggregation, sélectionnez Maximum pour Object Size.

-
Query conditions and output settings.
Cliquez sur Query. Deux objets correspondent aux conditions de la requête. La taille de l'objet le plus volumineux est de 434 Ko.

SDK Alibaba Cloud
Les exemples suivants permettent d'interroger les objets correspondant à des conditions spécifiées.
Java
Autres exemples : MetaSearch (SDK Java 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
Autres exemples : 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=100, # The maximum number of entries that can be returned. Valid values: 0 to 100.
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
Autres exemples : MetaSearch (SDK Go 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
Autres exemples : MetaSearch (SDK 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 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. );
Utiliser ossutil
Utilisez ossutil pour interroger les objets correspondants. Pour installer ossutil, consultez la rubrique Installer ossutil.
Interrogez les objets correspondants dans le 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\"}]}}"
Désactiver MetaSearch
La désactivation de MetaSearch n'affecte pas les données stockées. La réactivation du service déclenche une nouvelle analyse des fichiers existants et la reconstruction de l'index. Le temps nécessaire dépend du nombre de fichiers présents dans votre bucket.
La facturation s'arrête à l'heure suivant la désactivation de la fonctionnalité. La génération des factures pouvant être différée, vérifiez leur exactitude.
OSS console
Connectez-vous à la console OSS. Sur la page Data Indexing, cliquez sur Disable à côté de Metadata Management et suivez les instructions.

Alibaba Cloud SDK
Java
Exemples supplémentaires : 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
Exemples supplémentaires : 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
Exemples supplémentaires : 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
Exemples supplémentaires : 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
Cet exemple désactive MetaSearch pour le bucket examplebucket :
ossutil api close-meta-query --bucket examplebucket
Conditions de requête et paramètres de sortie
Conditions de requête
Utilisez ces conditions individuellement ou en combinaison.
Paramètres de sortie
Triez les résultats et agrégez les statistiques.
Object Sort Order : Triez par date de dernière modification, nom d'objet ou taille d'objet, dans l'ordre croissant, décroissant ou par défaut.
Data Aggregation : Effectuez des calculs sur les résultats de la requête, tels que le comptage d'éléments uniques, le regroupement et le comptage, la recherche de valeurs maximales ou minimales, le calcul de moyennes et la somme de valeurs.
API associées
Pour une personnalisation accrue, appelez directement les API REST. Vous devez gérer vous-même le calcul de la signature.
Activez la gestion des métadonnées avec OpenMetaQuery.
Interrogez les fichiers correspondants avec DoMetaQuery.
Désactivez la gestion des métadonnées avec CloseMetaQuery.
Facturation
-
La tarification de MetaSearch comprend les deux composants suivants :
-
Frais de la fonctionnalité MetaSearch
Il s'agit des frais de gestion des métadonnées d'objet, facturés au tarif standard pour l'indexation des données OSS. Consultez les frais d'indexation des données.
-
Frais de requête API
Des frais de requête API sont engagés lors des mises à jour incrémentielles de l'index des fichiers. Vous êtes facturé en fonction du nombre d'appels API. Le tableau suivant répertorie les requêtes API qui engendrent ces frais :
Actions
API
Nombre
Indexation d'un objet dans un bucket
HeadObject et GetObject
Appelé une fois par objet
Indexation d'un objet comportant des tags
GetObjectTag
Appelé une fois par objet avec tags
Indexation d'un objet comportant des métadonnées personnalisées
GetObjectMeta
Appelé une fois par objet avec métadonnées personnalisées
Indexation d'un lien symbolique
GetSymlink
Appelé une fois par lien symbolique
Analyse des objets dans un bucket
ListObjects
Appelé une fois pour chaque tranche de 1 000 objets analysés
-
Pour arrêter ces frais, désactivez MetaSearch.
FAQ
Construction lente de l'index de données pour les buckets volumineux
L'indexation traite environ 600 objets incrémentiels par seconde. Estimez le temps total en fonction du nombre d'objets de votre bucket.
Interroger la taille totale des objets par préfixe
Connectez-vous à la console OSS.
Dans le volet de navigation de gauche, cliquez sur Buckets. Sur la page qui s'affiche, cliquez sur le nom du bucket cible.
Dans le volet de navigation de gauche, choisissez .
-
Définissez Object Name sur Prefix Match et saisissez le préfixe :
random_files/. Laissez les autres paramètres avec leurs valeurs par défaut.
-
Configurez les Search Result Settings.
Pour Object Sort Order, sélectionnez Default.
-
Pour Data Aggregation, sélectionnez Sum de Object Size.

-
Cliquez sur Query Now. Les résultats affichent la taille totale de tous les objets avec le préfixe
random_files/.
Documentation connexe
MetaSearch permet de filtrer par date de dernière modification, classe de stockage, ACL et taille de fichier. Comment filtrer les fichiers dans OSS dans une plage de temps spécifiée.