我正在尝试在Neo4j中使用Ajax查询整个图数据库。下面是我的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");
}
});`
它将响应返回为:
{
"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":[]
}
为什么我无法获得关系?任何建议都会有所帮助。
注意-所有节点在Neo4j中通过关系连接。
你正在恢复关系。
[{标题:旅游,名称:旅游"},{}]
第二个映射是一个空映射,因为您的关系没有属性。
如果您在Neo4j浏览器中发出相同的查询,您可以看到行格式的结果相同:
如果您需要某种额外的元数据,如类型、开始节点、结束节点,您需要为您的查询指定rest
或graph
结果DataContent:
data: JSON.stringify({"statements": [{"statement": "MATCH (n) OPTIONAL MATCH (n)-[r]-() RETURN n,r"}, "resultDataContents":["row", "graph", "rest"]})
由您选择适合您需求的结果数据内容。
参考:http://neo4j.com/docs/stable/rest-api-transactional.html#rest-api-return-results-in-graph-format