Skip to content

Get all assets that have a specific Atlan tag

1.4.0 1.1.0

This example finds all assets that are assigned a specific Atlan tag — irrespective of whether they were directly assigned the tag or it was propagated.

Get all assets with a specific tag
1
2
3
4
5
6
7
AtlanClient client = Atlan.getDefaultClient(); // (1)
client.assets.select() // (2)
    .where(CompoundQuery.tagged(client, List.of("PII"))) // (3)
    .stream() // (4)
    .forEach(a -> { // (5)
        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. The CompoundQuery.tagged() helper method allows us to limit to assets that match at least one of potentially multiple values (since there could be many tags on an asset). The SDK will translate the provided Atlan tag into the necessary internal representation required for the search — you can just provide the human-readable names of the Atlan tags.
  4. The search will only run when you call the stream() method, which will then lazily-load each page of results into a stream.
  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 tag
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
from pyatlan.client.atlan import AtlanClient
from pyatlan.model.fluent_search import FluentSearch, CompoundQuery

client = AtlanClient()  # (1)
request = (
    FluentSearch()  # (2)
    .where(CompoundQuery.tagged(["PII"]))  # (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.
  3. The CompoundQuery.tagged() helper method allows us to limit to assets that match at least one of potentially multiple values (since there could be many tags on an asset). The SDK will translate the provided Atlan tag into the necessary internal representation required for the search — you can just provide the human-readable names of the Atlan tags.
  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 tag
1
2
3
4
5
6
7
val client = Atlan.getDefaultClient() // (1)
client.assets.select() // (2)
    .where(CompoundQuery.tagged(client, listOf("PII"))) // (3)
    .stream() // (4)
    .forEach { // (5)
        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. The CompoundQuery.tagged() helper method allows us to limit to assets that match at least one of potentially multiple values (since there could be many tags on an asset). The SDK will translate the provided Atlan tag into the necessary internal representation required for the search — you can just provide the human-readable names of the Atlan tags.
  4. The search will only run when you call the stream() method, which will then lazily-load each page of results into a stream.
  5. 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 Atlan tags, you first need to have the Atlan-internal hashed-string representation of the tags. 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
20
21
22
23
24
25
26
27
28
29
30
{
  "dsl": { // (1)
    "query": {
      "bool": { // (2)
        "minimum_should_match": "1", // (3)
        "should": [ // (4)
          {
            "terms": {
              "__traitNames": [ // (4)
                "wAI4bROOqCQzES8HCNso9F" // (5)
              ]
            }
          },
          {
            "terms": {
              "__propagatedTraitNames": [ // (6)
                "wAI4bROOqCQzES8HCNso9F" // (7)
              ]
            }
          }
        ]
      }
    },
    "track_total_hits": true
  },
  "suppressLogs": true,
  "showSearchScore": false,
  "excludeMeanings": false,
  "excludeClassifications": false
}
  1. Run a search to find the assets.
  2. To match both assets that are directly assigned the Atlan tag and those that were propagated the Atlan tag, use a bool query for multiple conditions.
  3. Define the minimum number of conditions that need to match on an asset to be included in the results. In this example, you want either a direct or propagated Atlan tag, so should match at least one of the conditions provided.
  4. Use __traitNames to match directly-classified assets.
  5. Use the Atlan-internal hashed-string representation of the Atlan tag.
  6. Use __propagatedTraitNames to match assets that have been propagated this Atlan tag.
  7. Once again, use the Atlan-internal hashed-string representation of the Atlan tag.