Available in version 0.11.3 and later.
_id fields. For example, a balance uses identity_id to point to the matching identity_id in the identities collection.
Retrieving related data
Useinclude_fields to tell the Search API which related collection to return as part of your results. The format is:
$collection_name(*)to include all fields$collection_name(field1,field2,field3)to include specific fields.
identities object populated with the identity details of the balance.
Response (all fields)
Response (specific fields)
Filter by related data
You can filter a collection using related data from another collection. For example, let’s say you want to only view identities that have a USD balance:- First, you’ll search for all identities –
/search/identities. - Then add a “balance” filter to only include identities linked to a USD balance.
- Finally, you can specify what balance fields you want to include in the results.
Response
The fields you include when filtering must be from the collection you are filtering by. In this example, we are filtering by balances, so we can only include fields from the balances collection.
- First, you’ll search for all balances –
/search/balances. - Next, add a “transactions” filter so you only return balances that were involved in a transaction where the destination matches the target balance.
- Finally, you can specify what transaction fields you want to include in the results.
Request
Merging / nesting joined fields
When the joined collection returns one result per document, the collection’s fields are returned as nested objects. For example, see our first example response:strategy:merge in your request.
Request
Merged response
Handling nested arrays
When a join returns more than one match, the Search API gives you an array. When there is only one match, it becomes an object. This can make the shape inconsistent. To keep it consistent, addstrategy:nest_array so the joined data is always returned as an array. Example:
Request
balances data is always an array, no matter how many results it contains.
Nested JOINs
You can stack JOINs to go deeper. For example, you can join a balance to its identity, then also join that same balance to its ledger in the same query.Response