5
votes

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.

2
Which version of Neo4j are you using?jjaderberg
I am using version 1.9pawan9977
102 degrees celsius is above water boiling point, for sure that'll give you fever :Pjotadepicas

2 Answers

7
votes

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
2
votes

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