1

I´ve already had a look at different post like this and this but nothing seems to be answered 100%. My current problem is, that I want to visualyze - and ideally - analyze my Neo4j-Graph with a library (or software/tool). The database-server is running on a remote (virtual) server and it seems that there is no chance to export the database to a format where I can work on with. I´ve tried exporting the graph in a .graphml-file to import this file in Gephi, but Gephi doesn´t find the properties. Gephi-streaming with apoc-procedures and the graph-streaming plugin also does not work, because it´s a remote server (also with the tool mentioned here). Now I´m currently testing around with Alchemy.js... So far, so good. But as it seems there´s no way to export the graph/query to the GraphJson-format? Is there really no "easy" way to export the data?

Thanks for your help in advance!

Community
  • 1
  • 1
Andy
  • 129
  • 1
  • 3
  • 15

1 Answers1

3

This is how I would proceed

Run this query from the post you mentioned in the Neo4j Browser or in any bolt driver:

MATCH (a)-[r]->(b)
WITH collect(
    {
        source: id(a),
        target: id(b),
        caption: type(r)
    }
) AS edges
RETURN edges

Now that you have loaded the data, you can simply download it as JSON using download button.(if you are using bolt driver ignore) download

Either you manually downloaded JSON from Neo4j Browser or you are using bolt driver, you will end up with something like this.

{
  "columns": [
    "edges"
  ],
  "data": [
    {
      "row": [
        [
          {
            "source": 31288,
            "target": 152,
            "caption": "HAS_PAYMENT_METHOD"
          }
        ]
      ],
      "meta": [
        null
      ],
      "graph": {
        "nodes": [

        ],
        "relationships": [

        ]
      }
    }
  ]

Now all you have to is to filter out data.row results and you are done. Probably using bolt driver is the better choice as you have to clean up data anyway and it doesnt run into issues with returning a lots of data to the browser(it might crash).

Update: added python version

from neo4j.v1 import GraphDatabase

driver = GraphDatabase.driver("bolt://localhost:7687", auth=("neo4j", "neo4j"))


session = driver.session()


result = session.run("MATCH (a)-[r]->(b) WITH collect({source: id(a),target: id(b),caption: type(r)}) AS edges RETURN edges")

for record in result:
    print(record["edges"])

Hope this helps

Tomaž Bratanič
  • 6,319
  • 2
  • 18
  • 31