Skip to content

Latest commit

 

History

History
302 lines (191 loc) · 13 KB

storage-blob-index-how-to.md

File metadata and controls

302 lines (191 loc) · 13 KB
title description titleSuffix author ms.author ms.date ms.service ms.topic ms.devlang ms.custom
Use blob index tags to manage and find data on Azure Blob Storage
See examples of how to use blob index tags to categorize, manage, and query for blob objects.
Azure Storage
normesta
normesta
07/21/2022
azure-blob-storage
how-to
csharp
devx-track-csharp, devx-track-azurepowershell, devx-track-azurecli

Use blob index tags to manage and find data on Azure Blob Storage

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.

To learn more about this feature along with known issues and limitations, see Manage and find Azure Blob data with blob index tags.

Upload a new blob with 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/write Azure resource provider operation via a custom Azure role.

  1. In the Azure portal, select your storage account.

  2. Navigate to the Containers option under Data storage, and select your container.

  3. Select the Upload button and browse your local file system to find a file to upload as a block blob.

  4. Expand the Advanced dropdown and go to the Blob Index Tags section.

  5. Input the key/value blob index tags that you want applied to your data.

  6. Select the Upload button to upload the blob.

    :::image type="content" source="media/storage-blob-index-concepts/blob-index-upload-data-with-tags.png" alt-text="Screenshot of the Azure portal showing how to upload a blob with index tags.":::

  1. Sign in to your Azure subscription with the Connect-AzAccount command and follow the on-screen directions.

    Connect-AzAccount
  2. If your identity is associated with more than one subscription, then set your active subscription. Then, get the storage account context.

    $context = Get-AzSubscription -SubscriptionId <subscription-id>
    Set-AzContext $context
    $storageAccount = Get-AzStorageAccount -ResourceGroupName "<resource-group-name>" -AccountName "<storage-account-name>"
    $ctx = $storageAccount.Context   
  3. Upload a blob by using the Set-AzStorageBlobContent command. Set tags by using the -Tag parameter.

    $containerName = "myContainer"
    $file = "C:\demo-file.txt"
    
    Set-AzStorageBlobContent -File $file -Container $containerName -Context $ctx -Tag @{"tag1" = "value1"; "tag2" = "value2" }
  1. Open the Azure Cloud Shell, or if you've installed the Azure CLI locally, open a command console application such as Windows PowerShell.

  2. Install the storage-preview extension.

    az extension add -n storage-preview
    
  3. If you're using Azure CLI locally, run the login command.

    az login
    
  4. 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.

  5. Upload a blob by using the az storage blob upload command. Set tags by using the --tags parameter.

    az storage blob upload --account-name mystorageaccount --container-name myContainer --name demo-file.txt --file C:\demo-file.txt --tags tag1=value1 tag2=value2 --auth-mode login
    

See Upload with index tags.


Get, set, and update blob index tags

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/read Azure 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/write Azure resource provider operation via a custom Azure role.

  1. In the Azure portal, select your storage account.

  2. Navigate to the Containers option under Data storage, select your container.

  3. Select your blob from the list of blobs within the selected container.

  4. The blob overview tab will display your blob's properties including any Blob Index Tags.

  5. You can get, set, modify, or delete any of the key/value index tags for your blob.

  6. Select the Save button to confirm any updates to your blob.

    :::image type="content" source="media/storage-blob-index-concepts/blob-index-get-set-tags.png" alt-text="Screenshot of the Azure portal showing how to get, set, update, and delete index tags on blobs.":::

  1. Sign in to your Azure subscription with the Connect-AzAccount command and follow the on-screen directions.

    Connect-AzAccount
  2. If your identity is associated with more than one subscription, then set your active subscription. Then, get the storage account context.

    $context = Get-AzSubscription -SubscriptionId <subscription-id>
    Set-AzContext $context
    $storageAccount = Get-AzStorageAccount -ResourceGroupName "<resource-group-name>" -AccountName "<storage-account-name>"
    $ctx = $storageAccount.Context   
  3. To get the tags of a blob, use the Get-AzStorageBlobTag command and set the -Blob parameter to the name of the blob.

    $containerName = "myContainer"
    $blobName = "myBlob" 
    Get-AzStorageBlobTag -Context $ctx -Container $containerName -Blob $blobName
  4. 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.

    $containerName = "myContainer"
    $blobName = "myBlob" 
    $tags = @{"tag1" = "value1"; "tag2" = "value2" }
    Set-AzStorageBlobTag -Context $ctx -Container $containerName -Blob $blobName -Tag $tags
  1. Open the Azure Cloud Shell, or if you've installed the Azure CLI locally, open a command console application such as Windows PowerShell.

  2. Install the storage-preview extension.

    az extension add -n storage-preview
    
  3. If you're using Azure CLI locally, run the login command.

    az login
    
  4. 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.

  5. 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
    
  6. 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
    

See Replace index tags


Filter and find data with 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/filter/action Azure 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.

  1. In the Azure portal, select your storage account.

  2. Navigate to the Containers option under Data storage, select your container.

  3. Select the Blob Index tags filter button to filter within the selected container.

  4. Enter a blob index tag key and tag value.

  5. Select the Blob Index tags filter button to add additional tag filters (up to 10).

    :::image type="content" source="media/storage-blob-index-concepts/blob-index-tag-filter-within-container.png" alt-text="Screenshot of the Azure portal showing how to Filter and find tagged blobs using index tags":::

  1. Sign in to your Azure subscription with the Connect-AzAccount command and follow the on-screen directions.

    Connect-AzAccount
  2. If your identity is associated with more than one subscription, then set your active subscription. Then, get the storage account context.

    $context = Get-AzSubscription -SubscriptionId <subscription-id>
    Set-AzContext $context
    $storageAccount = Get-AzStorageAccount -ResourceGroupName "<resource-group-name>" -AccountName "<storage-account-name>"
    $ctx = $storageAccount.Context   
  3. To find all blobs that match a specific blob tag, use the Get-AzStorageBlobByTag command.

    $filterExpression = """tag1""='value1'"
    Get-AzStorageBlobByTag -TagFilterSqlExpression $filterExpression -Context $ctx
  4. 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
  1. Open the Azure Cloud Shell, or if you've installed the Azure CLI locally, open a command console application such as Windows PowerShell.

  2. Install the storage-preview extension.

    az extension add -n storage-preview
    
  3. If you're using Azure CLI locally, run the login command.

    az login
    
  4. 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.

  5. 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
    
  6. 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
    

N/A


Next steps