i use py2neo to find get path ,my function like this :
-----------------------my funciton -----------------
def findrelationall1(graph_db,startmobile,endmobile):
querystring='''MATCH(catelyn:Person {usernbr:%s}), (drogo:Person {usernbr:%s})
MATCH p=(catelyn)-[*..100]-(drogo)
RETURN p'''
result=graph_db.run(querystring1)
for x in result :
dic1=dict(x)
print dic1.values()
return is :
[(c0d4730)-[:a1_a2_201705 {count:4}]->(bf795f0)<-[:b1_b2_201705
{count:4}]-(ae68e9e)]
what "(c0d4730) " is ? a node ?
how can i use this value to return a node and property ?
I think it is the internal id.
Try
from py2neo import remote remote(node)._id
See How to get automatic node ID from py2neo?
Related
I tested the following query in a Neo4j browser and it worked. Now I am trying to define a schema and query for a React app using the neo4j-graphql-js plugin/driver (import { neo4jgraphql } from "neo4j-graphql-js";). My issue is I do not know how to define a schema that will take 2 parameters, example: action(startTime: {epoch}, endTime: {epoch}). The action node in the DB has the following properties: action, timelist and timestamp.
MATCH (sec:Second)<-[:AT_TIME]-(act:action)-[:TARGET]->(obj:object)
WHERE act.timestamp >= 1499350389000 AND act.timestamp <= 1499350389000
RETURN sec, act, obj
Trying to check that one value (once tokenized) doesn't match another value in my document:
/foo/bar/baz/tokenize(value,',')[not(. =(/foo/biz/value/string(),'bing'))]
Specifically here, checking that /foo/bar/baz/value (which is 'ding,dong,bing') doesn't match /foo/biz/value/string() or the value 'bong'.
But I'm getting "Leading '/' cannot select the root node of the tree containing the context item: the context item is not a node"
Is there any way that I can do this in XPath, or do I need to get out into XQuery and start to worry about variables?
Given that you're using Saxon, you can take advantage of the fact that XPath 3.0 allows you to bind variables:
let $foo := /foo return $foo/bar/baz/tokenize(value,',')
[not(. =($foo/biz/value/string(),'bing'))]
or you could pull the expression out of the predicate:
let $exceptions := (/foo/biz/value/string(),'bing')
return /foo/bar/baz/tokenize(value,',')[not(. = $exceptions)]
If you want pure XPath 2.0 you can achieve the same with an ugly "for" binding:
for $foo in /foo return $foo/bar/baz/tokenize(value,',')
[not(. =($foo/biz/value/string(),'bing'))]
If you're in XSLT, of course, you can use current().
I am trying to add a relationship to nodes using Neo4J JDBC driver and have formed the following query :
MATCH (node1:USER {fameId : 'test1'}),(node2:BEAM {eventUId : 'E000000016'})
CREATE (node1)-[r:PERFORMED{type:'test'}]->(node2)`
When I try to run this query using:
mConnection.createStatement().execute("MATCH (node1:USER {fameId : 'test1'}),(node2:BEAM {eventUId : 'E000000016'}) CREATE (node1)-[r:PERFORMED{type:'test'}]->(node2)")
It gives me the following error :
Error executing query MATCH (node1:USER {fameId : 'test1'}),(node2:BEAM {eventUId : 'E000000016'}) CREATE (node1)-[r:PERFORMED{type:'test'}]->(node2)
MATCH (node1:USER {fameId : 'test2'}),(node2:BEAM {eventUId : 'E000000016'}) CREATE (node1)-[r:PERFORMED{type:'test'}]->(node2)
with params {}
Please help. I am not able to proceed further :(
I am able to create nodes and relationships through Java on a Neo4j database. When I try to access the created nodes in the next run I get this error:
Exception in thread "main" org.neo4j.graphdb.NotFoundException: Node 27 not found
In webadmin interface the dashboard shows the number of nodes/relationships created through Java, but when I issue this query: START n=node(*) RETURN n; I get only 1 node in the ouput.
(FYI I have installed Ne04j in my windows machine(local) and using embedded database java code to create nodes.)
Java code I used to connect to db:
final String dbpath = "C:\\neo4j-community-1.9.4\\data\\graph.db";
GraphDatabaseService graphdb = new GraphDatabaseFactory().newEmbeddedDatabase(dbpath);
The settings I have used in ne04j-server.properties are:
org.neo4j.server.database.location=/C:/neo4j-community-1.9.4/data/graph.db/
org.neo4j.server.webserver.https.keystore.location=data/keystore
org.neo4j.server.webadmin.rrdb.location=data/rrd
org.neo4j.server.webadmin.data.uri=/C:/neo4j-community-1.9.4/data/graph.db/
org.neo4j.server.webadmin.management.uri=/db/manage/
When I create node through Java the data/keystore file does not get populated, and only gets populated when creating a node through webadmin interface. Changing the path of keystore file to absolute path also did not work.
Can anybody point the mistake in this scenario, Thanks .
The problem was the nodes created were not comitted. To commit the nodes we got to give finish() :
try{
Transaction tx = graphdb.beginTx();
final String dbpath = "/C:/neo4j-community-1.9.4/data/graph.db/";
GraphDatabaseService graphdb = new GraphDatabaseFactory().newEmbeddedDatabase(dbpath);
Node n1 = graphdb.createNode();
n1.setProperty("type", "company");
n1.setProperty("location", "india");
....
...
}} catch(Exception e){
tx.failure();
} finally {
tx.success();
**tx.finish();**
}
Ranjith's answer was correct until recently, but tx.finish() has now been deprecated.
tx.close(); is now the correct way to commit or rollback the transaction - it will do one or the other depending on whether you've previously called tx.success().
They changed this so the transaction is autocloseable in a try with resources block.
Have you tried:
String dbpath = "C:/neo4j-community-1.9.4/data/graph.db";
I use the exactly query just as http://docs.neo4j.org/chunked/milestone/query-using.html says.
My Neo4j Kernel version is
Neo4j - Graph Database Kernel 2.0.0-M03
I don't know why?
It's ok for me to run
CREATE (_1 { `name`:"Emil" })
CREATE (_2:`German` { `name`:"Stefan", `surname`:"Plantikow" })
CREATE (_3 { `age`:34, `name`:"Peter" })
CREATE (_4:`Swedish` { `age`:36, `awesome`:true, `name`:"Andres", `surname`:"Taylor" })
CREATE _1-[:`KNOWS`]->_3
CREATE _2-[:`KNOWS`]->_4
CREATE _4-[:`KNOWS`]->_3
But I got Unknown error while using
match n:Swedish using index n:Swedish(surname)
where n.surname = 'Taylor'
return n
If your query explicitly mandates to use an index, you need to make sure that it exists.
So run before querying:
CREATE INDEX ON :Swedish(surname)