以JSON格式输出的密码

时间:2016-07-29 14:07:12

标签: neo4j

输入数据

MATCH (n) DETACH DELETE n;
CREATE (p:Provider {id:1, specialty:"Cardiology",        pcp:0});
CREATE (p:Provider {id:2, specialty:"Internal Medicine", pcp:1});
CREATE (p:Provider {id:3, specialty:"Family Practice",   pcp:1});
CREATE (p:Provider {id:4, specialty:"Radiology",         pcp:0});

MATCH (p1:Provider {id:1}), (p2:Provider {id:2}) CREATE 
        (p1)-[:SHARED {mbrid:1}]->(p2),
        (p1)-[:SHARED {mbrid:2}]->(p2),
        (p1)-[:SHARED {mbrid:2}]->(p2),
        (p1)-[:SHARED {mbrid:3}]->(p2);
MATCH (p1:Provider {id:2}), (p2:Provider {id:3}) CREATE 
        (p1)-[:SHARED {mbrid:4}]->(p2),
        (p1)-[:SHARED {mbrid:5}]->(p2);
MATCH (p1:Provider {id:1}), (p2:Provider {id:3}) CREATE 
        (p1)-[:SHARED {mbrid:6}]->(p2);
MATCH (p1:Provider {id:1}), (p2:Provider {id:4}) CREATE 
        (p1)-[:SHARED {mbrid:9}]->(p2),
        (p1)-[:SHARED {mbrid:10}]->(p2),
        (p1)-[:SHARED {mbrid:11}]->(p2),
        (p1)-[:SHARED {mbrid:12}]->(p2),
        (p1)-[:SHARED {mbrid:12}]->(p2);

CREATE INDEX ON :Provider(id);        

查询

MATCH (p1:Provider)-[s:SHARED]-(p2:Provider)
WHERE  p1.id<p2.id and (p1.pcp=0 or (p1.pcp=1 and p2.pcp=0))
WITH p1, p2, count(distinct s.mbrid) as cnt
WHERE cnt>1
RETURN p1, p2, cnt;

输出

+------------------------------------------------------------------------------------------------------+
| p1                                         | p2                                                | cnt |
+------------------------------------------------------------------------------------------------------+
| Node[0]{id:1,specialty:"Cardiology",pcp:0} | Node[1]{pcp:1,id:2,specialty:"Internal Medicine"} | 3   |
| Node[0]{id:1,specialty:"Cardiology",pcp:0} | Node[3]{id:4,specialty:"Radiology",pcp:0}         | 4   |
+------------------------------------------------------------------------------------------------------+

我需要输出格式如下。观察到ID为3的节点未在下面列出,因为它不在输出中。此外,输出节点索引为0,1,2并在链接中使用

{
    "nodes" : [
        {
            "specialty" : "Cardiology",
            "pcp" : 0
        },
        {
            "specialty" : "Internal Medicine",
            "pcp" : 1
        },
        {
            "specialty" : "Radiology",
            "pcp" : 0
        }
    ],
    "links" : [
        {
            "source" : 0,
            "target" : 1,
            "value" : 3
        },
        {
            "source" : 0,
            "target" : 2,
            "value" : 4
        }
    ]
}

我很感激有关如何创建它的任何输入/指针。

1 个答案:

答案 0 :(得分:0)

优化您的查询以仅输出您需要的节点,然后在Neo浏览器中单击“导出到文件”按钮(您刚刚输入的查询文本旁边)。然后选择Export JSON