简体   繁体   English

查询具有多个相同类型关系的节点

[英]Querying for nodes with multiple relationships of the same type

I'm just starting to learn about Neo4J and I thought up a question I haven't seen an answer to in the reading I've been doing so far. 我才刚刚开始学习Neo4J,我想了一个问题,到目前为止我一直在阅读中没有看到答案。

I believe it's possible for a Node to be connected to another Node with the same relationship multiple times. 我相信一个节点有可能多次连接到具有相同关系的另一个节点。

Is it possible to return only the nodes where the number of Relationship edges meets some criteria? 是否可以仅返回关系边数满足某些条件的节点?

Example: 例:

Friend is a node. 朋友是一个节点。 Poked is a relationship. 戳是一种关系。

  • Friend A has poked Friend B 朋友A戳了朋友B
  • Friend A has poked Friend B 朋友A戳了朋友B
  • Friend B has poked Friend C 朋友B戳了朋友C

How would I query this so only Friend A is selected because it has poked the same friend more than once? 我将如何查询此消息,以便仅选择“朋友A”,因为它多次戳了同一个朋友?

If it matters; 如果重要的话; I'll be using Java and Spring's Data Graph module. 我将使用Java和Spring的Data Graph模块。

I'm assuming you want to use Cypher. 我假设您要使用Cypher。 Who wouldn't, right? 谁不会,对吗?

Cypher doesn't have the SQL equivalent of HAVING, so you will have to do a little bit in your host language. Cypher没有等效于HAVING的SQL,因此您将不得不使用宿主语言做一些事情。 The query would look something like this: 查询如下所示:

START friendA=node:person(name="Michael") 
MATCH friendA-[:POKED]->friendB 
RETURN friendB, count(*)

Now, with the resulting iterable of maps, exclude from the final result all maps where count(*) is different from what you want it to be. 现在,有了映射的结果可迭代性,从最终结果中排除count(*)与您想要的不同的所有映射。

Does this make sense? 这有意义吗?

暂无
暂无

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

相关问题 相同类型的多个关系,但在相同的两个节点之间具有不同的属性 - Multiple relationships of the same type but with different properties between the same two nodes 查询具有多个关系(发送和接收)的节点 - Querying nodes with multiple relationships (outgoing and incoming) 使用Cypher在Neo4j中的两个节点之间创建相同类型的多个关系 - Creating multiple relationships of the same type between two nodes in Neo4j using Cypher 从csv在两个节点之间创建具有不同属性的相同类型的多个关系 - Create multiple relationships of same type with different properties between two nodes from csv 根据两个不同节点之间的关系查询节点 - Querying nodes based on relationships between two different nodes 使用参数创建多个节点和关系 - Create multiple nodes and relationships with parameters Cypher 查询每个节点具有的特定类型关系的数量,包括其子节点中的相同类型关系 - Cypher query to count the number of relationships of specific type that each node has, including same type relationships in their sub-nodes Neo4j-避免在密码的相同节点之间创建多个关系? - Neo4j- Avoid multiple relationships getting created between the same nodes in cypher? 仅返回两个节点之间的特定关系(来自一种类型的多个) - Return only particular relationships (from multiple of one type) between two nodes 在具有相同属性的节点之间创建关系 - Creating relationships between nodes with same properties
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM