简体   繁体   English

关于Neo4j属性的关系

[英]Neo4j Properties on relationship

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" . 假设我有两个节点“体温”和“发烧”,它们之间的关系名称为“cause”,属性为“degree Celsius”的值为“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. 现在我想要做的是编写一个密码查询,如果在MATCH子句中有属性值> 102.0,那么它必须检索发烧节点,否则不能。

I have no idea of how to write such a query other then creating such structure. 我不知道如何编写这样的查询,然后创建这样的结构。

Any help would be appreciated. 任何帮助,将不胜感激。

You can filter on relationship properties like you would node properties, in the WHERE clause. 您可以在WHERE子句中过滤关系属性,就像节点属性一样。 Just make sure you bind the relationship to an identifier in the MATCH clause. 只需确保将关系绑定到MATCH子句中的标识符即可。 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. 要使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. 只需确保在STARTMATCHWHERE子句中绑定要在CREATE子句中使用的不同节点或关系。 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 有时你可能不得不使用WITH将结果带到查询的新部分,但对于你的情况,首先尝试类似的东西

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, 假设“摄氏度”是关系“CAUSES”的属性,可以使用“where”子句指定属性值约束,如下所示,

Match t:BodyTemperature-[r:CAUSES]->f:Fever
Where r.degreeCelsius > 102.0
Return f

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM