Neo4j : When Query using an index hint , I got Unknown error - neo4j

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)

Related

neo4j-graphql-schema: Cypher query to Graphql Schema and query

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

py2neo execute cypher to find path

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?

Cannot access nodes created using java in neo4j database, neo4j-server.properties issues

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";

Getting NotInTransactionException while querying neo4j index

I am currently using neo4j 1.8.1 . I am getting NotInTransactionException , when I am querying the neo4j index to get some nodes.
Following is a simple query , which i am executing on neo4j
if (graphDb.index().existsForNodes("NODEINDEX")) {
IndexHits<Node> hits = graphDb.index().forNodes(NODEINDEX).query(query);
}
The following is stacktrace for the exception.
"message" : "Error fetching transaction for current thread",
"exception" : "NotInTransactionException",
"stacktrace" : [ "org.neo4j.kernel.impl.index.IndexConnectionBroker.getCurrentTransaction(IndexConnectionBroker.java:134)", "org.neo4j.kernel.impl.index.IndexConnectionBroker.acquireReadOnlyResourceConnection(IndexConnectionBroker.java:84)", "org.neo4j.index.impl.lucene.LuceneIndex.getReadOnlyConnection(LuceneIndex.java:105)", "org.neo4j.index.impl.lucene.LuceneIndex.query(LuceneIndex.java:245)", "org.neo4j.index.impl.lucene.LuceneIndex.query(LuceneIndex.java:227)", "org.neo4j.index.impl.lucene.LuceneIndex.query(LuceneIndex.java:238)", "com.uprr.netcontrol.starmap.neo4j.plugins.aggregate_node_status.NodeStatusHelper.getGraphNodes(NodeStatusHelper.java:39)",
I found the following in Neo4j api.
private Transaction getCurrentTransaction() throws NotInTransactionException
{
try
{
return transactionManager.getTransaction();
}
catch ( SystemException se )
{
throw new NotInTransactionException(
"Error fetching transaction for current thread", se );
}
}
Do we need to explicitly start a transaction for querying neo4j index?
Any thoughts?
Thanks
Here's a theory: I don't know if this is only an issue with the code pasted here but the check:
if (graphDb.index().existsForNodes("NODEINDEX"))
checks for the index named "NODEINDEX", however the actual query
graphDb.index().forNodes(NODEINDEX).query(query);
checks for the index named whatever is in the constant NODEINDEX. Those two are probably not the same and so it tries to create that index for you and fails due to not being in a transaction.
if there isn't an existing appropriate index, I think it'll create one before returning it; this operation needs to be wrapped in a transaction.

grails neo4j config not adding nodes

I created the application using the instructions here:
http://blog.armbruster-it.de/2009/10/example-neo4j-with-grails/
I then added to DataSource.groovy this:
grails {
neo4j {
type = "embedded"
location = "/usr/local/Cellar/neo4j/"
params = []
}
}
Where my graph.db is located at /usr/local/Cellar/neo4j/community-1.8.1-unix/libexec/data/graph.db
What should be going into this location. I am adding new ndoes but when I run
start n=node(*) return n;
in the shell there is no new data. Thanks!
I believe your location should point right up to
/usr/local/Cellar/neo4j/community-1.8.1-unix/libexec/data/graph.db
since that is where your neo4j database is located

Resources