Use faceted search
Faceted search is a powerful tool that allows you to filter and retrieve REST resources based on multiple criteria or attributes, such as labels, annotations, status, and dates. This is especially useful when managing large sets of resources that need to be filtered efficiently.
Example: Basic faceted search
Here is an example of a simple faceted search using labels:
- TypeScript
- Java
const result = await client.credentials.credentialSearch({
filter: [
{
labels: {
operator: 'EQUAL',
value: 'employment',
}
},
},
],
});
var searchResult = client.credentials()
.credentialSearch(CredentialSearchRequest.builder()
.filter(List.of(CredentialFilter.builder()
.labels(List.of(CredentialFilterLabelsItem.equal(
KeyEqualLabelKeyLabelValue.builder()
.key("value")
.value("employment")
.build()
))).build()
)).build()
);
Example: Advanced faceted search with multiple criteria
The example below covers the case of finding credentials of a specific credential type (documentType
) that has a specific linked verifiable credential (previouslyIssuedVC
):
- TypeScript
- Java
const result = await client.credentials.credentialSearch({
filter: [
{
data: {
type: {
operator: 'IN',
values: [documentType.getCredentialTerm()],
},
linkedCredentials: {
operator: 'IN',
values: [previouslyIssuedVC.toLinkedCredential().id],
},
},
},
],
});
var advancedSearchResult = client.credentials()
.credentialSearch(CredentialSearchRequest.builder()
.filter(List.of(CredentialFilter.builder()
.data(CredentialFilterData.builder()
.type(CredentialFilterDataType.in(new NestedInPrimitiveString(
List.of(documentType.getCredentialTerm())
)))
.linkedCredentials(CredentialFilterDataLinkedCredentials.in(new NestedInPrimitiveString(
List.of(previouslyIssuedVC.descriptor().id())
)))
.build())
.build()))
.build());