cancel
Showing results for 
Search instead for 
Did you mean: 

Head's Up! These forums are read-only. All users and content have migrated. Please join us at community.neo4j.com.

Help with an allocation query

I'm trying to wrap my head around how I would need to write a query. I have an item of income that has attributes fund, allocation type, and class. That item is entity level (connected by an :IS_ENTITY_LEVEL_TO relationship) to exactly one entity, and for purposes of this, that entity allocates to exactly one other entity. There are multiple allocations tagged with different allocation type, class, and fund, as well as an allocation order. My challenge is to figure out how to match that item of income to the allocation that it should have. I want to match this item of income to its proper allocation (:ALLOCATES_TO relationship) based on the shared attributes, and then if there are multiple matching allocations, choose the one that has the most matching attributes, then with the highest allocation order. How can I accomplish this?

Here's the cypher query to create the above.

CREATE 
  (`0` :Income {trialBalanceId:'1',amount:'100'}) ,
  (`1` :Fund {name:'9'}) ,
  (`2` :`Allocation Type` {name:'Capital'}) ,
  (`3` :Class {name:'1'}) ,
  (`4` :Entity {entityId:'922'}) ,
  (`5` :Entity {entityId:'146'}) ,
  (`0`)-[:``:IS_OF_FUND`` ]->(`1`),
  (`0`)-[:``:IS_OF_ALLOCATION_TYPE`` ]->(`2`),
  (`0`)-[:``:IS_OF_CLASS`` ]->(`3`),
  (`0`)-[:``:IS_ENTITY_LEVEL_TO`` ]->(`4`),
  (`4`)-[:``:ALLOCATES_TO`` {allocationCodeId:'1',fund:'9',allocationType:'Capital',class:'2'}]->(`5`),
  (`4`)-[:``:ALLOCATES_TO`` {allocationCodeId:'2',fund:'9',allocationType:'Capital',class:'1'}]->(`5`),
  (`4`)-[:``:ALLOCATES_TO`` {allocationCodeId:'3',fund:'10',allocationType:'Capital',class:'1'}]->(`5`)
2 REPLIES 2

intouch_vivek
Graph Steward

Hi @repalmervi,

Thanks for providing the small data set. I have few queries

  1. What is the logic behind replicating property of Nodes to the relationship?
  2. Your requirement is not very clear to me .. kindly explain.

@intouch.vivek The logic is that the ALLOCATES TO relationship uses the same attributes as the Income node. Each item of income is tagged with Fund, Class, and AllocationType, and this is also how the amount is allocated as it goes from Entity to Entity. I need to choose the correct path from entity to entity based on the highest number of total matching attributes, then the allocation order.

So if I had Income item A with Class 1, Fund 10, and AllocationType Capital, and I had 2 ALLOCATES_TO: relationships 1) Class 1, Fund 10, Order 1, and 2) Fund 10, Order 2, then Income Item A would match with relationships 1 and 2, but because relationship 2 had a higher order and had at least one matching property, Income Item A would follow allocation relationship 2. I think I need to be able to build a list of relationships where the attributes match the income, then order them by the allocation order and pick the highest one.