I have a Cypher script for populating a Neo4j (2.2.3) database. Currently, the names of all the CSV files are hard coded. Is there a way to parameterize the CSV files, in case I'd like to switch to a different web server or switch to using the local file system?
Update
I forgot to mention that my use case is via neo4j-shell. Is there also a way to define parameters for use by the shell or can that only be done through the REST API? Thanks!
You can use parameters in the shell, just export them as "environment" variables.
List them with env:
export name=Tim
env
match (p:Person {firstName:{name}}) return p;
Yes, the URL for the CSV file is a string in the Cypher query so you can parameterize it like any other Cypher query. Check out the docs here and here.
Related
I am trying to import multiple rdf files into neo4j as described here
My problem is that even though elements have the same rdf:ID they end up being imported as different neo4j nodes with different uris prefixed by the different file names like file:/x.xml#_00141f6c-69b1-4a1a-a83b-333d0bb9d586 and file:/y.xml#_00141f6c-69b1-4a1a-a83b-333d0bb9d586.
I have tried to use:
call semantics.addNamespacePrefix("local","file:/x.xml#")
call semantics.addNamespacePrefix("local","file:/y.xml#")
before importing but to no avail. I have additionally tried to set handleVocabUris: "MAP" as an option for the import function.
Is there an import option that I am missing which allows these nodes to be unified? Is there generally an elegant way to reunify them after importing?
My current workaround is to copy each file into a temp file before loading so that the prefixes are the same. Neo4j joins the nodes with the same uri into one, which is exactly what I need.
Still happy to hear about an elegant way to do this though..
I am trying to import data into neo4j using LOAD CSV
The resource file contains names of all the nodes I need to create
resource1
resource2
resource3
In another file I have all the properties of that resource
resource1,name,xyz
resource1,year,1920
resource1,age,100
resource2,length,300
resource2,age,30
I Managed to load the nodes into neo4j but how do I import the second file so that I can add the data to that particular node as properties, I tried setting the key dynamically
USING PERIODIC COMMIT
LOAD CSV FROM 'file:///infobox.csv' AS line
MERGE (:Node{line[1]:line[2]})
neo4j doesn't allow setting the key dynamically?
How do I solve this?
Natively, Neo4j doesn't allow setting the key dynamically. But you can install APOC Procedures use apoc.create.setProperty to do this.
Try something like:
USING PERIODIC COMMIT
LOAD CSV FROM 'file:///infobox.csv' AS line
// match the node by resource1, resource2, etc
MATCH(node:Node{resource_id : line[0]})
CALL apoc.create.setProperty(node, line[1], line[2])
RETURN *
Note: Remember to install APOC procedures according the version of Neo4j you are using. Take a look in the Version Compatibility Matrix.
I have an employee database with 1800 employees and 45000 messages in between them. I am trying to export the results of the following query into a csv file by clicking the export option in the neo4j browser.
LOAD CSV WITH HEADERS FROM
'file:///employees.csv' AS line
WITH line
MATCH(e:Employee{pkey:line.profile_key})-[r:Message]->(b:Employee) RETURN
e.pkey, b.pkey, COUNT(r)
ORDER BY e.pkey;
But its not working. I only get the initial 100 rows.I have also changed the number of rows to 10000 in the browser settings, but then again after the execution of the query my browser stops responding and closes automatically. I am using neo4j community edition 3.2.1 on windows. Is there any other way to export the results other than the browser option in windows? Thanks in advance!
You might want to use the APOC procedures and run them from the Cypher shell. Example :
neo4j> CALL apoc.export.csv.query("MATCH(p:Part) RETURN p.name","/var/tmp/parts.csv", {});
This does require you to setup the apoc plugin and add the following parameter to neo4j.conf
apoc.export.file.enabled=true
Hope this helps,
Tom
So it looks like the gremlin API requires a url to import a GraphML file to the server (http://docs.neo4j.org/chunked/stable/gremlin-plugin.html#rest-api-load-a-sample-graph). I was hoping there'd be some API where you could just POST the GraphML to it, does something like this exist?
I realise I could write a Neo4j extension to essentially do this, but I was wondering if one already existed...
There a shell extension at https://github.com/jexp/neo4j-shell-tools#graphml-import providing this feature. It should not be too hard to convert that into a server extension.
If the graph is not huge, perhaps you can try passing the file as a string to the gremlin extension and use the script in the doc you cited. Therefore your gremlin script expects a String variable that contains your graph and it creates the file (by writing the string graph to the file):
def fos= new FileOutputStream('path_to_my_file.xml')
fos.write(myGraphAsString)
You can then load this file:
g.clear()
g.loadGraphML('file:/path_to_my_file.xml')
So I code using ruby on rails and the default database is sqlite, which is amazing for development. there is no setup time, no need for connection etc. What really sucks is the output on the command line. when i do a query to list all the contents of a table for example. I just get a dump of text, unlike when you use MySql, the CLI formats the results of the queries nicely (with headers in a table). I am also aware of "headers on" and the commands you can type to format the results of sqlite but those are temporary and I am looking for a more permanent way to format the results so i do not have to do it every-time.
It appears that you can specify SQL statements and metadata statements in an init file and pass this file as the -init parameter.