How do I get relations of one type only for entities of a specific entity type?

Question

I need all relations of one relation type, for example <RelationType>, but only where the related entities are of one entity type, such as Organization. relations/_scan returns relations, but I can't find a filter for the entity type of the start or end entity. Is there one?

Answer

No. relations/_scan and relations/_search filter only on the fields indexed for relations. These include the relation type, its attributes, and startObject and endObject, which hold entity IDs, not entity types. To filter on the entity type, use the Search Connections API instead. It first finds entities with an entity filter, then returns their relations of the types you list. {TenantURL} is https://<environment>.reltio.com/reltio/api/<tenantId>.

POST {TenantURL}/entities/_searchConnections?max=25&returnFullRelations=false&options=searchRelationsWithFilter
Authorization: Bearer <access_token>
Content-Type: application/json

{
  "filter": "equals(type,'configuration/entityTypes/Organization')",
  "connections": [
    {
      "outRelations": [ { "uri": "configuration/relationTypes/<RelationType>" } ]
    }
  ]
}

Reading the response

  • The response has an entities array and a relations array. Each relation has its type, startObject and endObject. There's no option to leave out entities, so read only the relations array if that's all you need.
  • outRelations returns relations where the found entity is the start object. If the entity is the end object of the relation, use inRelations instead.
  • returnFullRelations=false, the default, returns only the relation type, start and end entity URIs, attributes, and crosswalks, which keeps the response small.
  • max limits the entities found by the entity filter, not the connected entities. Use connectedEntitiesMax in the body to limit the connected entities returned for each entity.

Scanning all relations of one type

If you don't need the entity type, relations/_scan returns every relation of a type. Pass filter and max in the query string on the first request, for example POST {TenantURL}/relations/_scan?filter=(equals(relation_type,'<RelationType>'))&max=100. Then send the cursor from each response in the body of the next request.

 

Was this article helpful?
0 out of 0 found this helpful

Comments

0 comments

Article is closed for comments.