Use blob index tags to manage and find data on Azure Blob Storage
Article
Blob index tags categorize data in your storage account using key-value tag attributes. These tags are automatically indexed and exposed as a searchable multi-dimensional index to easily find data. This article shows you how to set, get, and find data using blob index tags.
This task can be performed by a Storage Blob Data Owner or a security principal that has been given permission to the Microsoft.Storage/storageAccounts/blobServices/containers/blobs/tags/writeAzure resource provider operation via a custom Azure role.
Getting blob index tags can be performed by a Storage Blob Data Owner or a security principal that has been given permission to the Microsoft.Storage/storageAccounts/blobServices/containers/blobs/tags/readAzure resource provider operation via a custom Azure role.
Setting and updating blob index tags can be performed by a Storage Blob Data Owner or a security principal that has been given permission to the Microsoft.Storage/storageAccounts/blobServices/containers/blobs/tags/writeAzure resource provider operation via a custom Azure role.
To set the tags of a blob, use the Set-AzStorageBlobTag command. Set the -Blob parameter to the name of the blob, and set the -Tag parameter to a collection of name and value pairs.
Open the Azure Cloud Shell, or if you've installed the Azure CLI locally, open a command console application such as Windows PowerShell.
Install the storage-preview extension.
az extension add -n storage-preview
If you're using Azure CLI locally, run the login command.
az login
If your identity is associated with more than one subscription, then set your active subscription to subscription of the storage account.
az account set --subscription <subscription-id>
Replace the <subscription-id> placeholder value with the ID of your subscription.
To get the tags of a blob, use the az storage blob tag list command and set the --name parameter to the name of the blob.
az storage blob tag list --account-name mystorageaccount --container-name myContainer --name demo-file.txt --auth-mode login
To set the tags of a blob, use the az storage blob tag set command. Set the --name parameter to the name of the blob, and set the --tags parameter to a collection of name and value pairs.
az storage blob tag set --account-name mystorageaccount --container-name myContainer --name demo-file.txt --tags tag1=value1 tag2=value2 --auth-mode login
This task can be performed by a Storage Blob Data Owner or a security principal that has been given permission to the Microsoft.Storage/storageAccounts/blobServices/containers/blobs/filter/actionAzure resource provider operation via a custom Azure role.
Note
You can't use index tags to retrieve previous versions. Tags for previous versions aren't passed to the blob index engine. For more information, see Conditions and known issues.
Within the Azure portal, the blob index tags filter automatically applies the @container parameter to scope your selected container. If you wish to filter and find tagged data across your entire storage account, use our REST API, SDKs, or tools.
To find blobs only in a specific container, include the container name in the -TagFilterSqlExpression.
$filterExpression = "@container='myContainer' AND ""tag1""='value1'"
Get-AzStorageBlobByTag -TagFilterSqlExpression $filterExpression -Context $ctx
Open the Azure Cloud Shell, or if you've installed the Azure CLI locally, open a command console application such as Windows PowerShell.
Install the storage-preview extension.
az extension add -n storage-preview
If you're using Azure CLI locally, run the login command.
az login
If your identity is associated with more than one subscription, then set your active subscription to subscription of the storage account.
az account set --subscription <subscription-id>
Replace the <subscription-id> placeholder value with the ID of your subscription.
To find all blobs that match a specific blob tag, use the az storage blob filter command.
az storage blob filter --account-name mystorageaccount --tag-filter """tag1""='value1' and ""tag2""='value2'" --auth-mode login
To find blobs only in a specific container, include the container name in the --tag-filter parameter.
az storage blob filter --account-name mystorageaccount --tag-filter """@container""='myContainer' and ""tag1""='value1' and ""tag2""='value2'" --auth-mode login