在 Azure 门户中,"blob 索引标记" 筛选器会自动应用 @container 参数以限定所选容器的范围。Within the Azure portal, the blob index tags filter automatically applies the @container parameter to scope your selected container. 如果要跨整个存储帐户筛选和查找标记的数据,请使用我们的 REST API、Sdk 或工具。If you wish to filter and find tagged data across your entire storage account, use our REST API, SDKs, or tools.
在 Azure 门户中,选择存储帐户。In the Azure portal, select your storage account.
导航到 " Blob 服务" 下的 "容器" 选项,选择容器Navigate to the Containers option under Blob service, select your container
选择“Blob 索引标记筛选器”按钮,在所选容器内进行筛选Select the Blob Index tags filter button to filter within the selected container
输入 blob 索引标记键和标记值Enter a blob index tag key and tag value
选择“Blob 索引标记筛选器”按钮,以便添加更多标记筛选器(最多 10 个)Select the Blob Index tags filter button to add additional tag filters (up to 10)
static async Task FindBlobsByTagsExample()
{
BlobServiceClient serviceClient = new BlobServiceClient(ConnectionString);
BlobContainerClient container1 = serviceClient.GetBlobContainerClient("mycontainer");
BlobContainerClient container2 = serviceClient.GetBlobContainerClient("mycontainer2");
// Blob index queries and selection
String singleEqualityQuery = @"""Archive"" = 'false'";
String andQuery = @"""Archive"" = 'false' AND ""Priority"" = '01'";
String rangeQuery = @"""Date"" >= '2020-04-20' AND ""Date"" <= '2020-04-30'";
String containerScopedQuery = @"@container = 'mycontainer' AND ""Archive"" = 'false'";
String queryToUse = containerScopedQuery;
try
{
// Create a container
await container1.CreateIfNotExistsAsync();
await container2.CreateIfNotExistsAsync();
// Create append blobs
AppendBlobClient appendBlobWithTags0 = container1.GetAppendBlobClient("myAppendBlob00.logs");
AppendBlobClient appendBlobWithTags1 = container1.GetAppendBlobClient("myAppendBlob01.logs");
AppendBlobClient appendBlobWithTags2 = container1.GetAppendBlobClient("myAppendBlob02.logs");
AppendBlobClient appendBlobWithTags3 = container2.GetAppendBlobClient("myAppendBlob03.logs");
AppendBlobClient appendBlobWithTags4 = container2.GetAppendBlobClient("myAppendBlob04.logs");
AppendBlobClient appendBlobWithTags5 = container2.GetAppendBlobClient("myAppendBlob05.logs");
// Blob index tags to upload
CreateAppendBlobOptions appendOptions = new CreateAppendBlobOptions();
appendOptions.Tags = new Dictionary
{
{ "Archive", "false" },
{ "Priority", "01" },
{ "Date", "2020-04-20" }
};
CreateAppendBlobOptions appendOptions2 = new CreateAppendBlobOptions();
appendOptions2.Tags = new Dictionary
{
{ "Archive", "true" },
{ "Priority", "02" },
{ "Date", "2020-04-24" }
};
// Upload data with tags set on creation
await appendBlobWithTags0.CreateAsync(appendOptions);
await appendBlobWithTags1.CreateAsync(appendOptions);
await appendBlobWithTags2.CreateAsync(appendOptions2);
await appendBlobWithTags3.CreateAsync(appendOptions);
await appendBlobWithTags4.CreateAsync(appendOptions2);
await appendBlobWithTags5.CreateAsync(appendOptions2);
// Find Blobs given a tags query
Console.WriteLine("Find Blob by Tags query: " + queryToUse + Environment.NewLine);
List blobs = new List();
await foreach (TaggedBlobItem taggedBlobItem in serviceClient.FindBlobsByTagsAsync(queryToUse))
{
blobs.Add(taggedBlobItem);
}
foreach (var filteredBlob in blobs)
{
Console.WriteLine($"BlobIndex result: ContainerName= {filteredBlob.ContainerName}, " +
$"BlobName= {filteredBlob.Name}");
}
}
finally
{
}
}