I am new to Neo4j and playing arround with it to see wether we can use it in one of our projects. Assume I have graph created as follows:
CREATE (n:PORTFOLIO {NAME:"PF_R", VALUE_RF_A:"0.5"})
CREATE (n:PORTFOLIO {NAME:"PF_A", VALUE_RF_A:"1.0", VALUE_RF_B:"2.0"})
CREATE (n:PORTFOLIO {NAME:"PF_B", VALUE_RF_A:"1.1", VALUE_RF_C:"3.0"})
MATCH (r:PORTFOLIO), (a:PORTFOLIO), (b:PORTFOLIO)
WHERE r.NAME="PF_R" AND a.NAME="PF_A" AND b.NAME="PF_B"
CREATE (r)-[s1:has_sub_pf]->(a), (r)-[s2:has_sub_pf]->(b)
RETURN r,a,b
=> Question: How does one (or more?) MATCH/SET statement for changing the graph look like such that the following Query returns me the node "PF_R":
MATCH (x:PORTFOLIO)
WHERE x.NAME = "PF_R"
AND x.VALUE_RF_A="2.6" AND x.VALUE_RF_B:"2.0" AND VALUE_RF_C:"3.0"
RETURN x
So the properties "VALUE_*" are aggregated upwards in the tree from the leaves to the root. In more detail:
I want the attributes "VALUE_RF_*" to be aggregated (added) upwards from the leaves to the root (or added to the next upper level, iff not existing). Concrete: The PORTFOLIO node with name "PF_A" is a leaf so nothing changes there, but the properties "VALUE_RF_A" and "VALUE_RF_B" should be added to its parent such that PORTFOLIO node with name "PF_R" then has properties "VALUE_RF_A" and "VALUE_RF_B" with values "1.5" (1.0+0.5) and "2.0" (not yet existing). Att the same time (or afterwards) the properties "VALUE_RF_A" and "VALUE_RF_C" of the (leaf) PORTFOLIO node with name "PF_B" also should be added to the properties of node "PF_R", so that in the end that one has properties "VALUE_RF_A", "VALUE_RF_B" and "VALUE_RF_C" with values "2.6","2.0" and "3.0".
Oh, Btw: It would be perfect, if this could be done in only one statement and not per (root)->leaf path. May approach would have been to do such an aggregation per "layer" of the tree, starting from the leaves, upwards to the parents. And it would be even nicer, if the statement(s) to be used do not rely on the specific names of the properties, but only aggregate the values of those having the same name (this is btw. another problem I have: Can I find nodes in the tree having properties with the same names: is there a way in Neo4J to query the "meta"/schema-information?)
Thanks for your support!
MATCH
/SET
statements that would change the graph to match that query, but I don't understand your comment about "aggregating upwards in the tree". - jjaderberg