Skip to content

Get all assets that have custom metadata

With any value

1.4.0 1.1.0

This example finds all assets with a particular custom metadata attribute populated — irrespective of the specific value of the attribute.

Get all assets with a custom metadata attribute populated
1
2
3
4
5
6
7
8
AtlanClient client = Atlan.getDefaultClient(); // (1)
client.assets.select() // (2)
    .where(CustomMetadataField.of(client, "RACI", "Responsible").hasAnyValue()) // (3)
    ._includesOnResults(client.getCustomMetadataCache().getAttributesForSearchResults("RACI")) // (4)
    .stream() // (5)
    .forEach(a -> { // (6)
        log.info("Asset: {}", a);
    });
  1. Start with a client to run the search through. For the default client, you can always use Atlan.getDefaultClient().
  2. To search across all assets, you can use the assets.select() convenience method on a client.
  3. When searching for custom metadata attributes, you can construct a CustomMetadataField to start a clause that will match a custom metadata property. Since you are searching for the custom metadata attribute itself, there is no enum for the custom metadata or its property names, so these must be provided as strings. (The CustomMetadataField will handle translating these from their human-readable values to the Atlan-internal ID strings needed for the search.)

    The hasAnyValue() predicate allows you to limit to assets that have any value for this custom metadata attribute.

  4. Since you are searching for custom metadata, you probably want to include the values for custom metadata in each search result. This getAttributesForSearchResults() helper method will return all of the custom attributes within the RACI custom metadata structure. These will be encoded in the specific form required by the search for you.

    Note the use of _includesOnResults

    Since the getAttributesForSearchResults() helper will return a list of strings, you'll need to use the special _includesOnResults() method to add these for inclusion.

  5. The search will only run when you call the stream() method, which will then lazily-load each page of results into a stream.

  6. This is the pattern for iterating through all results (across pages) covered in the Searching for assets portion of the SDK documentation.
Get all assets with a custom metadata attribute populated
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
from pyatlan.cache.custom_metadata_cache import CustomMetadataCache
from pyatlan.client.atlan import AtlanClient
from pyatlan.model.fields.atlan_fields import CustomMetadataField
from pyatlan.model.fluent_search import FluentSearch

client = AtlanClient()  # (1)
request = (
    FluentSearch(_includes_on_results=CustomMetadataCache.get_attributes_for_search_results("RACI"))  # (2)
    .where(CustomMetadataField(set_name="RACI", attribute_name="Responsible").has_any_value())  # (3)
).to_request()  # (4)
for result in client.asset.search(request):  # (5)
    print(result)
  1. Start with a client to run the search through. For the default client, you can always use AtlanClient().
  2. To search across all assets, you can use a FluentSearch object.

    Since you are searching for custom metadata, you probably want to include the values for custom metadata in each search result. This get_attributes_for_search_results() helper method will return all of the custom attributes within the RACI custom metadata structure. These will be encoded in the specific form required by the search for you.

    Note the use of _includes_on_results

    Since the get_attributes_for_search_results() helper will return a list of strings, you'll need to use the special _includes_on_results parameter to add these for inclusion.

  3. When searching for custom metadata attributes, you can construct a CustomMetadataField to start a clause that will match a custom metadata property. Since you are searching for the custom metadata attribute itself, there is no enum for the custom metadata or its property names, so these must be provided as strings. (The CustomMetadataField will handle translating these from their human-readable values to the Atlan-internal ID strings needed for the search.)

    The has_any_value() predicate allows you to limit to assets that have any value for this custom metadata attribute.

  4. You can then translate the fluent search into an index search request.

  5. This is the pattern for iterating through all results (across pages) covered in the Searching for assets portion of the SDK documentation.
Get all assets with a custom metadata attribute populated
1
2
3
4
5
6
7
8
val client = Atlan.getDefaultClient() // (1)
client.assets.select() // (2)
    .where(CustomMetadataField.of(client, "RACI", "Responsible").hasAnyValue()) // (3)
    ._includesOnResults(client.customMetadataCache.getAttributesForSearchResults("RACI")) // (4)
    .stream() // (5)
    .forEach { // (6)
        log.info { "Asset: $it" }
    }
  1. Start with a client to run the search through. For the default client, you can always use Atlan.getDefaultClient().
  2. To search across all assets, you can use the assets.select() convenience method on a client.
  3. When searching for custom metadata attributes, you can construct a CustomMetadataField to start a clause that will match a custom metadata property. Since you are searching for the custom metadata attribute itself, there is no enum for the custom metadata or its property names, so these must be provided as strings. (The CustomMetadataField will handle translating these from their human-readable values to the Atlan-internal ID strings needed for the search.)

    The hasAnyValue() predicate allows you to limit to assets that have any value for this custom metadata attribute.

  4. Since you are searching for custom metadata, you probably want to include the values for custom metadata in each search result. This getAttributesForSearchResults() helper method will return all of the custom attributes within the RACI custom metadata structure. These will be encoded in the specific form required by the search for you.

    Note the use of _includesOnResults

    Since the getAttributesForSearchResults() helper will return a list of strings, you'll need to use the special _includesOnResults() method to add these for inclusion.

  5. The search will only run when you call the stream() method, which will then lazily-load each page of results into a stream.

  6. This is the pattern for iterating through all results (across pages) covered in the Searching for assets portion of the SDK documentation.

Requires multiple API operations

Before you can search for custom metadata, you first need to have the Atlan-internal hashed-string representation of the custom metadata property. You will likely need to first retrieve the hashed-string representation.

POST /api/meta/search/indexsearch
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
{
  "dsl": { // (1)
    "query": { // (2)
      "exists": { // (3)
        "field": "omrIzGB4oYlZrFKfTIUz6D" // (4)
      }
    },
    "track_total_hits": true
  },
  "attributes": [
    "UQot6bU4XcGcIx8gAQ1dsW.omrIzGB4oYlZrFKfTIUz6D" // (5)
  ],
  "suppressLogs": true,
  "showSearchScore": false,
  "excludeMeanings": false,
  "excludeClassifications": false
}
  1. Run a search to find the assets.
  2. For a search with only a single condition, we can directly provide the condition.
  3. You can use the exists criteria to match any assets that have some value (no matter what that value is) for a given field.
  4. Use the Atlan-internal hashed-string representation of the custom metadata field name.
  5. Include the Atlan-internal hashed-string representation of the custom metadata field name in the attributes list, so you can see the value of the custom metadata on each result. In this attributes list it needs to be written as <CustomMetadata>.<Attribute>, using the hashed-string representation for both pieces.

With a specific value

1.4.0 1.1.0

This example finds all assets with a particular custom metadata attribute populated — with a specific value for the attribute.

Get all assets with a specific custom metadata attribute value
1
2
3
4
5
6
7
8
AtlanClient client = Atlan.getDefaultClient(); // (1)
client.assets.select() // (2)
    .where(CustomMetadataField.of(client, "RACI", "Responsible").eq("This exact value")) // (3)
    ._includesOnResults(client.getCustomMetadataCache().getAttributesForSearchResults("RACI")) // (4)
    .stream() // (5)
    .forEach(a -> { // (6)
        log.info("Asset: {}", a);
    });
  1. Start with a client to run the search through. For the default client, you can always use Atlan.getDefaultClient().
  2. To search across all assets, you can use the assets.select() convenience method on a client.
  3. When searching for custom metadata attributes, you can construct a CustomMetadataField to start a clause that will match a custom metadata property. Since you are searching for the custom metadata attribute itself, there is no enum for the custom metadata or its property names, so these must be provided as strings. (The CustomMetadataField will handle translating these from their human-readable values to the Atlan-internal ID strings needed for the search.)

    The eq() predicate allows you to limit to assets that have only the exact value provided for this custom metadata attribute.

  4. Since you are searching for custom metadata, you probably want to include the values for custom metadata in each search result. This getAttributesForSearchResults() helper method will return all of the custom attributes within the RACI custom metadata structure. These will be encoded in the specific form required by the search for you.

    Note the use of _includesOnResults

    Since the getAttributesForSearchResults() helper will return a list of strings, you'll need to use the special _includesOnResults() method to add these for inclusion.

  5. The search will only run when you call the stream() method, which will then lazily-load each page of results into a stream.

  6. This is the pattern for iterating through all results (across pages) covered in the Searching for assets portion of the SDK documentation.
Get all assets with a custom metadata attribute populated
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
from pyatlan.cache.custom_metadata_cache import CustomMetadataCache
from pyatlan.client.atlan import AtlanClient
from pyatlan.model.fields.atlan_fields import CustomMetadataField
from pyatlan.model.fluent_search import FluentSearch

client = AtlanClient()  # (1)
request = (
    FluentSearch(_includes_on_results=CustomMetadataCache.get_attributes_for_search_results("RACI"))  # (2)
    .where(CustomMetadataField(set_name="RACI", attribute_name="Responsible").eq("This exact value"))  # (3)
).to_request()  # (4)
for result in client.asset.search(request):  # (5)
    print(result)
  1. Start with a client to run the search through. For the default client, you can always use AtlanClient().
  2. To search across all assets, you can use a FluentSearch object.

    Since you are searching for custom metadata, you probably want to include the values for custom metadata in each search result. This get_attributes_for_search_results() helper method will return all of the custom attributes within the RACI custom metadata structure. These will be encoded in the specific form required by the search for you.

    Note the use of _includes_on_results

    Since the get_attributes_for_search_results() helper will return a list of strings, you'll need to use the special _includes_on_results parameter to add these for inclusion.

  3. When searching for custom metadata attributes, you can construct a CustomMetadataField to start a clause that will match a custom metadata property. Since you are searching for the custom metadata attribute itself, there is no enum for the custom metadata or its property names, so these must be provided as strings. (The CustomMetadataField will handle translating these from their human-readable values to the Atlan-internal ID strings needed for the search.)

    The eq() predicate allows you to limit to assets that have only the exact value provided for this custom metadata attribute.

  4. You can then translate the fluent search into an index search request.

  5. This is the pattern for iterating through all results (across pages) covered in the Searching for assets portion of the SDK documentation.
Get all assets with a specific custom metadata attribute value
1
2
3
4
5
6
7
8
val client = Atlan.getDefaultClient() // (1)
client.assets.select() // (2)
    .where(CustomMetadataField.of(client, "RACI", "Responsible").eq("This exact value")) // (3)
    ._includesOnResults(client.customMetadataCache.getAttributesForSearchResults("RACI")) // (4)
    .stream() // (5)
    .forEach { // (6)
        log.info { "Asset: $it" }
    }
  1. Start with a client to run the search through. For the default client, you can always use Atlan.getDefaultClient().
  2. To search across all assets, you can use the assets.select() convenience method on a client.
  3. When searching for custom metadata attributes, you can construct a CustomMetadataField to start a clause that will match a custom metadata property. Since you are searching for the custom metadata attribute itself, there is no enum for the custom metadata or its property names, so these must be provided as strings. (The CustomMetadataField will handle translating these from their human-readable values to the Atlan-internal ID strings needed for the search.)

    The eq() predicate allows you to limit to assets that have only the exact value provided for this custom metadata attribute.

  4. Since you are searching for custom metadata, you probably want to include the values for custom metadata in each search result. This getAttributesForSearchResults() helper method will return all of the custom attributes within the RACI custom metadata structure. These will be encoded in the specific form required by the search for you.

    Note the use of _includesOnResults

    Since the getAttributesForSearchResults() helper will return a list of strings, you'll need to use the special _includesOnResults() method to add these for inclusion.

  5. The search will only run when you call the stream() method, which will then lazily-load each page of results into a stream.

  6. This is the pattern for iterating through all results (across pages) covered in the Searching for assets portion of the SDK documentation.

Requires multiple API operations

Before you can search for custom metadata, you first need to have the Atlan-internal hashed-string representation of the custom metadata property. You will likely need to first retrieve the hashed-string representation.

POST /api/meta/search/indexsearch
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
{
  "dsl": { // (1)
    "query": { // (2)
      "term": { // (3)
        "omrIzGB4oYlZrFKfTIUz6D": { // (4)
          "value": "This exact value" // (5)
        }
      }
    },
    "track_total_hits": true
  },
  "attributes": [
    "UQot6bU4XcGcIx8gAQ1dsW.omrIzGB4oYlZrFKfTIUz6D" // (6)
  ],
  "suppressLogs": true,
  "showSearchScore": false,
  "excludeMeanings": false,
  "excludeClassifications": false
}
  1. Run a search to find the assets.
  2. For a search with only a single condition, we can directly provide the condition.
  3. You can use the term query to exactly match a value on assets, for a given field.
  4. Use the Atlan-internal hashed-string representation of the custom metadata field name.
  5. Provide the exact value you want to match in that custom metadata property.
  6. Include the Atlan-internal hashed-string representation of the custom metadata field name in the attributes list, so you can see the value of the custom metadata on each result. In this attributes list it needs to be written as <CustomMetadata>.<Attribute>, using the hashed-string representation for both pieces.