简体   繁体   English

在Neo4j中使用Ajax使用Cypher查询整个图数据库

[英]Query whole graph DB with Cypher using Ajax in Neo4j

I am trying to query whole graph db using Ajax in Neo4j. 我正在尝试在Neo4j中使用Ajax查询整个图数据库。 Below is my ajax code. 下面是我的ajax代码。

$.ajax({  
    type: "POST",  
    url: "http://localhost:7474/db/data/transaction/commit ",  
    dataType: "json",  
    contentType: "application/json;charset=UTF-8",  
    data: JSON.stringify({"statements": [{"statement": "MATCH (n) OPTIONAL MATCH (n)-[r]-() RETURN n,r"}]}),  
    success: function (data, textStatus, jqXHR) {  
        $(".neo4jResponse").html(JSON.stringify(data));  
    },  
    error: function (jqXHR, textStatus, errorThrown) {  
        alert("Error");  
    }  
});`

It's returning the response as: 它返回的响应为:

{    
    "results":
    [
        {
            "columns":["n","r"],
            "data":
            [
                {"row":[{"title":"Tourism","name":"Tourism"},{}]},
                {"row":[{"title":"Tourism","name":"Tourism"},{}]},
                {"row":[{"title":"Coastal Debris","name":"Coastal Debris"},{}]},
                {"row":[{"title":"Coastal Debris","name":"Coastal Debris"},{}]},
                {"row":[{"title":"Quality","name":"Quality"},{}]},
                {"row":[{"title":"Quality","name":"Quality"},{}]},
                {"row":[{"title":"Recreational Value","name":"Recreational Value"},{}]},
                {"row":[{"title":"Recreational Value","name":"Recreational Value"},{}]},
                {"row":[{"title":"Eco-Tourism Incentives","name":"Eco-Tourism Incentives"},{}]},
                {"row":[{"title":"Eco-Tourism Incentives","name":"Eco-Tourism Incentives"},{}]},
                {"row":[{"title":"Eco-Tourism","name":"Eco-Tourism"},{}]},
                {"row":[{"title":"Eco-Tourism","name":"Eco-Tourism"},{}]}
            ]
        }
    ],
    "errors":[]
}

Why I am not able to get the relationship? 为什么我无法建立关系? Any suggestions would help. 任何建议都会有所帮助。

Note - All the nodes are connected in Neo4j through relationship. 注-所有节点都通过关系连接到Neo4j。

You are getting the relationships back. 您正在恢复关系。

[{"title":"Tourism","name":"Tourism"},{}]

The second map is an empty map because your relationships do not have properties. 第二张地图是空的地图,因为您的关系没有属性。

If you issue the same query in the Neo4j browser you can see that the result is the same for the rows format : 如果在Neo4j浏览器中发出相同的查询,则可以看到行格式的结果相同:

在此处输入图片说明

If you need some kind of additional metadata, like types, start nodes, end nodes, you need to specify the rest or graph resultDataContent for your query : 如果您需要某种其他类型的元数据,例如类型,开始节点,结束节点,则需要为查询指定restgraph resultDataContent:

data: JSON.stringify({"statements": [{"statement": "MATCH (n) OPTIONAL MATCH (n)-[r]-() RETURN n,r"}, "resultDataContents":["row", "graph", "rest"]})

Up to you to pick up the result data content that fit your needs. 由您自行选择适合您需求的结果数据内容。

Reference : http://neo4j.com/docs/stable/rest-api-transactional.html#rest-api-return-results-in-graph-format 参考: http : //neo4j.com/docs/stable/rest-api-transactional.html#rest-api-return-results-in-graph-format

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM