Head's Up! These forums are read-only. All users and content have migrated. Please join us at community.neo4j.com.
04-09-2021 07:46 AM
Greetings,
I have a question about how to perform operations between children nodes. I have a document node(s) with about ~1200 children each containing a single value of a named metric. I'd like to pull two specific related node to create a ratio, then repeat for a list of parent nodes.
I'm thinking of using a user def function or a change in the modeling, but hoping for another opinion.
for example:
match( documents:Document )-[:hasMetric]->(x:Metric {name="revenue })
match( documents:Document )-[:hasMetric]->(y:Metric {name="profit })
...
// for every document, return y.value / x.value
the model is very simple right now as I do not want to over complicate it yet, but is that my issue? Maybe each named metric needs its own relation type, but that would be 1,000s of relation types on millions of nodes.
thanks for any reply, and please let me know how to clarify.
Cheers.
Solved! Go to Solution.
04-12-2021 12:25 AM
Hi sullirobert,
welcome to the community!
I am not sure if I got the whole problem and feel free to clarify if there is more but for your example you could do something like:
MATCH (x:Metric {name:"revenue"})<-[:hasMetric]-( documents:Document )-[:hasMetric]->(y:Metric {name:"profit" })
RETURN y.value/x.value
If you have more than two metrics, probably something like the following will work:
MATCH ( documents: Document )
WITH documents
MATCH (documents)-[:hasMetric]->(x:Metric {name:"revenue" }), (documents)-[:hasMetric]->(y:Metric {name:"profit" }), (documents)-[:hasMetric]->(z:Metric {name:"cost" })
RETURN ...
Regards,
Elena
04-12-2021 12:25 AM
Hi sullirobert,
welcome to the community!
I am not sure if I got the whole problem and feel free to clarify if there is more but for your example you could do something like:
MATCH (x:Metric {name:"revenue"})<-[:hasMetric]-( documents:Document )-[:hasMetric]->(y:Metric {name:"profit" })
RETURN y.value/x.value
If you have more than two metrics, probably something like the following will work:
MATCH ( documents: Document )
WITH documents
MATCH (documents)-[:hasMetric]->(x:Metric {name:"revenue" }), (documents)-[:hasMetric]->(y:Metric {name:"profit" }), (documents)-[:hasMetric]->(z:Metric {name:"cost" })
RETURN ...
Regards,
Elena
04-12-2021 01:19 PM
yup. works! thank you
All the sessions of the conference are now available online