neo4j - 如何从浏览器中的先前结果中恢复数据?

标签 neo4j cypher

我有一个在 neo4j 网络浏览器中运行的查询:

MATCH p=(z)<-[*]-(a)-[:foo]->(b) WHERE b.value = "bar" return p

这返回了大量连接的节点。发生的事情似乎删除了所有这些节点(在一个单独的事件中),但我仍然有旧查询的输出。浏览器的代码部分列出了响应数据:
 ...
 "graph": {
        "nodes": [
          {
            "id": "1148578",
            "labels": [
              "text"
            ],
            "properties": {
              "value": "bar",
              "timestamp": 1478747946867
            }
          },
   ...

有没有办法让我从旧查询的输出中重新创建所有这些数据?

最佳答案

您可以使用 apoc.load.json 去做这个。请注意,此解决方案不会保留内部节点 ID。 APOC 是一个扩展内置 Neo4j 功能的过程库。

给定 JSON 文件

{"graph": {
        "nodes": [
          {
            "id": "32496",
            "labels": [
              "Person"
            ],
            "properties": {
              "born": 1967,
              "name": "Carrie-Anne Moss"
            }
          },
          {
            "id": "32505",
            "labels": [
              "Movie"
            ],
            "properties": {
              "tagline": "Evil has its winning ways",
              "title": "The Devil's Advocate",
              "released": 1997
            }
          },
          {
            "id": "32494",
            "labels": [
              "Movie"
            ],
            "properties": {
              "tagline": "Welcome to the Real World",
              "title": "The Matrix",
              "released": 1999
            }
          },
          {
            "id": "32495",
            "labels": [
              "Person"
            ],
            "properties": {
              "born": 1964,
              "name": "Keanu Reeves"
            }
          }
        ],
        "relationships": [
          {
            "id": "83204",
            "type": "ACTED_IN",
            "startNode": "32495",
            "endNode": "32505",
            "properties": {
              "role": "Kevin Lomax"
            }
          },
          {
            "id": "83183",
            "type": "ACTED_IN",
            "startNode": "32496",
            "endNode": "32494",
            "properties": {
              "role": "Trinity"
            }
          },
          {
            "id": "83182",
            "type": "ACTED_IN",
            "startNode": "32495",
            "endNode": "32494",
            "properties": {
              "role": "Neo"
            }
          }
        ]
      }
    }
  } 

我们可以使用以下查询重新创建图形:
CALL apoc.load.json("https://dl.dropboxusercontent.com/u/67572426/small_movie_graph.json") YIELD value AS row
WITH row, row.graph.nodes AS nodes
UNWIND nodes AS node
CALL apoc.create.node(node.labels, node.properties) YIELD node AS n
SET n.id = node.id
WITH row
UNWIND row.graph.relationships AS rel
MATCH (a) WHERE a.id = rel.startNode
MATCH (b) WHERE b.id = rel.endNode
CALL apoc.create.relationship(a, rel.type, rel.properties, b) YIELD rel AS r
RETURN *

关于neo4j - 如何从浏览器中的先前结果中恢复数据?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40532812/

相关文章:

Neo4j 的可扩展性

java - 使用 neo4j 密码查询删除关系的结束节点

neo4j - 返回 cypher 中关系列表的开始和结束节点

java - Cypher 查询给出 java.lang.OutOfMemoryError

neo4j - cypher查询获取遍历中的中间对象和最短路径

neo4j - 如何避免neo4j的死锁

java - 使@Fetch 与接口(interface)一起工作

neo4j - 如何在 neo4j 密码中获得唯一列表?

neo4j - 是否可以根据密码查询中的某些条件创建变量并进行分配?

neo4j - 如何在neo4j中使用cypher获取节点属性列表