Skip to content

Get all assets that are linked to a specific term

This example finds all assets that are linked to a specific glossary term. (And could be extended to do find assets linked to any one of a number of glossary terms.) In this specific example we will find any assets linked to a glossary term named Revenue in a glossary named Metrics.

You'll need the qualifiedName of the glossary term

To find the assets linked to the glossary term, you'll need to search using the qualifiedName of the term. This is not the human-readable name you see in the UI. So this example is split into two parts:

  1. Finding the qualifiedName of the glossary term from its human-readable name and the result of (1).
  2. Finding all assets linked to that glossary term.

1.4.0 1.1.0

For example:

Find qualifiedName of the term
1
2
GlossaryTerm term = GlossaryTerm.findByName("Revenue", "Concepts"); // (1)
String termQualifiedName = term.getQualifiedName(); // (2)
  1. The GlossaryTerm.findByName() helper method will retrieve the glossary term by its human-readable name, given the name of the glossary in which it should exist. If the term does not exist (within that glossary), it will throw a NotFoundException.
  2. If no exception was thrown, you can retrieve the qualifiedName of the glossary term.
Get all assets linked to a specific term
3
4
5
6
7
8
9
AtlanClient client = Atlan.getDefaultClient(); // (1)
client.assets.select() // (2)
    .where(CompoundQuery.assignedTerm(List.of(termQualifiedName))) // (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. When searching for assets linked to one or more terms, you need to use the qualifiedName of the term(s). (This example shows searching for just one term, but you could search for any number of them in the list. The search will find assets that are assigned at least one of those terms in the list.)
  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.
Find qualifiedName of the term
1
2
3
4
5
6
from pyatlan.client.atlan import AtlanClient
from pyatlan.model.fluent_search import FluentSearch, CompoundQuery

client = AtlanClient()  # (1)
term = client.asset.find_term_by_name("Revenue", "Concepts")  # (2)
term_qualified_name = term.qualified_name  # (3)
  1. Start with a client to run the search through. For the default client, you can always use AtlanClient().
  2. The asset.find_term_by_name() helper method will retrieve the glossary term by its human-readable name, given the name of the glossary in which it should exist. If the term does not exist (within that glossary), it will throw a NotFoundError.
  3. If no exception was thrown, you can retrieve the qualified_name of the glossary term.
Get all assets linked to a specific term
 7
 8
 9
10
11
12
request = (
    FluentSearch()  # (1)
    .where(CompoundQuery.assigned_term([term_qualified_name]))  # (2)
).to_request()  # (3)
for result in client.asset.search(request):  # (4)
    print(result)
  1. To search across all assets, you can use a FluentSearch object.
  2. When searching for assets linked to a given term, you need to use the qualified_name of the term.
  3. You can then translate the fluent search into an index search request.
  4. This is the pattern for iterating through all results (across pages) covered in the Searching for assets portion of the SDK documentation.
Find qualifiedName of the term
1
2
val term = GlossaryTerm.findByName("Revenue", "Concepts") // (1)
val termQualifiedName = term.qualifiedName // (2)
  1. The GlossaryTerm.findByName() helper method will retrieve the glossary term by its human-readable name, given the name of the glossary in which it should exist. If the term does not exist (within that glossary), it will throw a NotFoundException.
  2. If no exception was thrown, you can retrieve the qualifiedName of the glossary term.
Get all assets linked to a specific term
3
4
5
6
7
8
9
val client = Atlan.getDefaultClient() // (1)
client.assets.select() // (2)
    .where(CompoundQuery.assignedTerm(java.util.List.of(termQualifiedName))) // (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. When searching for assets linked to one or more terms, you need to use the qualifiedName of the term(s). (This example shows searching for just one term, but you could search for any number of them in the list. The search will find assets that are assigned at least one of those terms in the list.)
  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 assets linked to a term, you first need to have the qualifiedName of the term. You will likely need to first find the term by its name.

POST /api/meta/search/indexsearch
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
{
  "dsl": { // (1)
    "query": { // (2)
      "terms": { // (3)
        "__meanings": [ // (4)
          "5h2wMbSbWtRN1V1b05Mtb@LD5Tb30qbuYCZKsmFRpmS" // (5)
        ]
      }
    },
    "track_total_hits": true
  },
  "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 terms query to exactly match a value on assets, for a given field, against a list of possible matches.
  4. To find terms, match against the __meanings field.
  5. Provide the exact value of the qualifiedName for the term for which you want to find linked assets.