Search code examples
pythoncsvneo4jcypherpy2neo

Connecting to Neo4j database after importing CSV


I have imported my csv files using the neo4j-admin according to the documentation using the following command

/bin/neo4j-admin import --mode=csv --nodes all_nodes_ne_header.csv,all_nodes_ne.csv --relationships all_relations_ne_header.csv,all_relations_ne.csv

the result looks like

IMPORT DONE in 15s 997ms.
Imported:
  19354 nodes
  11759454 relationships
  58062 properties
Peak memory usage: 1.03 GB

and I can see a file called graph.db in the data/databases folder.

I go to python and do:

from py2neo import Graph, Node, Relationship, Database
%matplotlib inline
%load_ext cypher

default_db = Database(db = Database())
graph = Graph("bolt://localhost:3637")

and after running my query I get the following:

Format: (http|https)://username:password@hostname:port/db/name
...
ConnectionError: HTTPConnectionPool(host='localhost', port=7474): Max retries exceeded with url: /db/data/ (Caused by NewConnectionError('<urllib3.connection.HTTPConnection object at 0x12e269790>: Failed to establish a new connection: [Errno 61] Connection refused'))

I guess I am not doing the connection correctly within Python and didn't find anywhere in the documentation how to do it. Basically, I have not set any password, username and even don't the port. I generated a report using neo4j-admin report and there was not anything relevant either. therefore, I appreciate your comments on how I can build the connection and start querying from python.


Solution

  • One has to to the config file and edit the following line in the neo4j.config

    # The name of the database to mount
    dbms.active_database=graph.db
    

    then can run ./bin/neo4j consol

    the output should end like

    Starting Neo4j.
    2019-12-01 23:42:14.731+0000 INFO  ======== Neo4j 3.5.3 ========
    2019-12-01 23:42:14.743+0000 INFO  Starting...
    2019-12-01 23:42:16.599+0000 INFO  Bolt enabled on 127.0.0.1:7687.
    2019-12-01 23:42:18.122+0000 INFO  Started.
    2019-12-01 23:42:19.065+0000 INFO  Remote interface available at http://localhost:7474/
    

    then going back to the jupyter notebook ...