cypher

Issue of casting Node neo4j

a 夏天 提交于 2019-12-25 00:32:23
问题 My code is below, As per the documentation it should have given me the node values but it is throwing me exception Exception in thread "main" java.lang.ClassCastException: scala.collection.convert.Wrappers$SeqWrapper cannot be cast to org.neo4j.graphdb.Node at com.neo4j.performance.FetchData.main(FetchData.java:32) I'm using Neo4j 2.2.2. import org.neo4j.graphdb.Node; import org.neo4j.graphdb.Result; import org.neo4j.graphdb.Transaction; import java.util.Iterator; import org.neo4j.helpers

How to extract a graph out of Neo4J and reconstruct it in the programming language

狂风中的少年 提交于 2019-12-24 20:12:22
问题 Consider I have a bunch of connected nodes in Neo4J, forming a tree or a graph or whatever, and I want to have them in the programming language that I'm using (I'm using Java but that's not important). I know I can have them all with a single cypher query like this: MATCH (n0:Root)-[:Child*0..]->(nx:Node) WHERE ID(n0) = 1 RETURN nx; But the problem I have here is that once returned to Java, I don't know which node is connected to which! How can I return the data so I can reconstruct the graph

How to count the numbers of node types in the Neo4j graph?

若如初见. 提交于 2019-12-24 19:37:01
问题 MATCH (p:Product), (s:Student), (b:Boy), (a:Attribute) RETURN count(distinct(p)), count(distinct(s)), count(distinct(b)), count(distinct(a)) I want to know how many counts of each node types in the graph using this query. However, the Neo4j Browser gives a warning saying that this query produces a cartesian product. Is there a better way to write the query? 回答1: To get a variety of statistics for your DB, including a count of the number of nodes for every label, you can use the APOC function

Limiting Cypher queries

本秂侑毒 提交于 2019-12-24 19:11:57
问题 I am currently using a neo4j database with 50000 nodes and 2 million relationships to perform cypher MATCH queries, like the one below: start startnode = node(42660), endnode = node(30561) match startnode-[r*1..3]->endnode return r; This query by itself provides 443 rows, but I only want Cypher to find 5 matches and return those only. Allow me to clarify: I do not just want Cypher to return only 5 results, I also want cypher to STOP querying once it finds 5 results. I DO NOT want Cypher to

Performing match by index lookup with cypher

狂风中的少年 提交于 2019-12-24 19:09:57
问题 I have a dense node problem and to get around this I've been using indexing to perform some matching using the native Java API, but I've been giving Cypher a second look and wanted to know if this could be done. Currently my pattern looks like this in Java Code: Node startNode = db.getNodeById(1); Index<Relationship> relationshipIndex = db.index.forRelationships("relationships"); for(Relationship relationship1 : startNode.getRelationships(Direction.OUT)) { Node otherNode = relationship

How to avoid cycle in neo4j cypher queries

孤街浪徒 提交于 2019-12-24 18:25:10
问题 I have friend-friend data model which has two relationships between any two friend nodes based on how one friend defines the other friend. For example, User "A" can define user "B" as 'FRIEND' and "B" can define "A" as 'BUDDY'. The problems is, when I try to get the 3rd degree of relationship of user "A", it returns user "B", where as the actual result should be "D" only. MATCH(a:Users {first_name : "A"}) -[:BUDDY|FRIEND*3] -> (b) RETURN a,b OR MATCH (a)-[]-(b)-[]-(c)-[]-(d) WHERE a.first

cypher how get relation between every two node and the distance from start node?

喜欢而已 提交于 2019-12-24 18:17:05
问题 I have some nodes and relation like A -> B ->C -> D ; and B->D So the B C D is a loop, now I want get all relations and each relation distance from node A; I expect result like: {startNode: A, endNode: B, rel:FRIEND, distanceFromAtoEndnode: 1}, {startNode: B, endNode: C, rel:FRIEND, distanceFromAtoEndnode: 2}, {startNode: C, endNode: D, rel:FRIEND, distanceFromAtoEndnode: 3}, {startNode: B, endNode: D, rel:FRIEND, distanceFromAtoEndnode: 2} and my cypher: match p=(n:Person {name:"A"})-[r*1..9

Neo4j.rb : transfer all relationships before replacing a node by another

杀马特。学长 韩版系。学妹 提交于 2019-12-24 17:21:12
问题 I'm trying to transfert all ingoing and outgoing relationships (including their properties) from a node to another, before deleting the first one. they both have the same label. The discussion started here : Neo4j Cypher : transfer all relationships before replacing a node by another node_query = Neo4j::Session.query.match(old_node: {uuid: node1.uuid}).match(new_node: {uuid: node2.uuid}) types = node_query.match('node-[rel]-()').pluck('DISTINCT type(rel)') types.each do |type| node_query

NEO4J: Couldn't load the external resource at: file:/var/lib/neo4j/import/

我只是一个虾纸丫 提交于 2019-12-24 17:19:08
问题 I am running Neo4J on Docker within Vagrant. I am attempting to LOAD CSV WITH HEADERS from a file within the /import/ directory (I had to move my file there) via a cURL request. My request looks something like this: "LOAD CSV WITH HEADERS FROM \"file:///insert-neo4j.csv\" AS row ... This provides me with the following error: {"results":[],"errors [{"code":"Neo.ClientError.Statement.ExternalResourceFailed","message":"Couldn't load the external resource at: file:/var/lib/neo4j/import/insert

Complex query with agregation in where clause

感情迁移 提交于 2019-12-24 17:00:03
问题 Suppose that i have a graph in which for each pair of nodes m,n of type BallT there can be a node k of type BallD that connects them through relationships of type Rel, that is, there can be multiple patterns of the kind p=(m:BallT)-[r:Rel]-(k:BallD)-[s:Rel]-(n:BallT) . For a given node m (satisfying for example m.key="whatever" ) let's call Nmn the number of BallD connecting m and some node n and N the total number of BallD nodes. For this given node m how can i found all nodes n such that