Say I have two nodes "Body Temperature" and "Fever" , The relationship between them has name "causes" and property as "degree Celsius" has value "102.0" . Now What I want to do is write a cypher query in which if there is property value > 102.0 in MATCH clause then it must retrieve fever node otherwise not.
I have no idea of how to write such a query other then creating such structure.
Any help would be appreciated.
The Neo4j Graph Data Science Library provides multiple operations to work with relationships and their properties stored in a projected graphs. Relationship properties are either added during the graph projection or when using the mutate mode of our graph algorithms.
Properties are stored as a linked list of property records, each holding a key and value and pointing to the next property. Each node and relationship references its first property record. The Nodes also reference the first relationship in its relationship chain. Each Relationship references its start and end node.
Relationships describes a connection between a source node and a target node. Relationships always has a direction (one direction). Relationships must have a type (one type) to define (classify) what type of relationship they are.
You sometimes find cases where you need to connect more data to a relationship than can be fully captured in the properties. In other words, you want a relationship that connects more than two nodes. Mathematics allows this, with the concept of a hyperedge. This is impossible in Neo4j.
You can filter on relationship properties like you would node properties, in the WHERE
clause. Just make sure you bind the relationship to an identifier in the MATCH
clause. I don't understand your model (is the temperature a property of the causation?) but you could try something like
MATCH (body_temperature) <-[r:CAUSES]- (fever)
WHERE r.degreeCelsius > 102
Is that what you are looking for?
Edit
To make a CREATE
clause dependent on some condition you can state your condition as a pattern which only matches the cases where you want something created, and then just proceed to create. Just make sure that in your START
, MATCH
and WHERE
clauses you bind the different nodes or relationships that you want to use in your CREATE
clause. Sometimes you might have to use WITH
to carry results to a new part of your query, but for your case first try something like
START bodyTemp = node:MyIndex(name="Body Temperature"), fever = node:MyIndex(name="Fever")
WHERE HAS(bodyTemp.degreeCelsius) AND bodyTemp.degreeCelsius > 102.0
CREATE bodyTemp -[:CAUSES]-> FEVER
Suppose the "degree Celsius" is the property of the relationship "CAUSES", you can use the "where" clause to specify the property value constraint as follows,
Match t:BodyTemperature-[r:CAUSES]->f:Fever
Where r.degreeCelsius > 102.0
Return f
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With