'How to sort and filter using metadata in Google Cloud Storage?

I am using metadata on blobs in a Google Cloud Storage bucket to store important information regarding a specific blob. I would like to use the Sort and filter functionality that is available from the Cloud Storage UI a bit more extensively. The available filter properties seem to be:

  • Name contains
  • Name prefix
  • Size (bytes)
  • Type
  • Created on
  • Created before
  • Created after
  • Storage class
  • Last modified on
  • Last modified before
  • Last modified after
  • Public access
  • Version history
  • Encryption
  • Retention expires on
  • Retention expires before
  • Retention expires after
  • Holds

But no filter property for metadata is available. However, some functionality to filter on metadata seems to be present. For example. If there are two files present, one with the metadata key-value pair special_key: true and the other one no metadata tag and I filter (in the UI) with Sort and filter, special_key then the only file that remains is the one with the tag.

However, I cannot filter more specifically on the label, for example special_key = true to only show the blobs with a certain value of a metadata key. Is there a way to do this? A similar question has been asked here, but the best answer solves this by using the SDK and not the UI itself, which is the preferred solution.



Solution 1:[1]

As mentioned in the document :

In the Cloud Console list of objects for a bucket, you can filter the objects you see by specifying a prefix in the Filter by object or folder name prefix... text box, located above the list of objects. This filter displays objects beginning with the specified prefix. The prefix only filters objects in your current bucket view: it does not select objects contained in folders.

For your case, you can do this answer_1 and answer_2 :

You would need to list all the objects and then filter at the client side. Another option, if it's possible to rename your objects, would be to construct your object names such that the metadata values on which you want to filter are built into the beginning of the object names. You could then use a prefix filter on the listing request.

There is one Public issue tracker created on the similar issue , you can take a look.

For more information, you can refer to the documentation.

Solution 2:[2]

how about: GCS --> Cloud Functions --> some database; use the db index for filtering/searching

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Divyani Yadav
Solution 2 Tom Bal