背景:
我正在使用本地运行的Neo4J实例(位于localhost:7474),并通过Java适配器访问它,该适配器通过REST API(使用Jersey)使用Cypher,并使数据可在同一服务器上运行的Grails应用程序访问。
问题:
是否可以通过REST API使用Cypher查询Neo4J db并返回节点的URI?现在,我可以检查Neo4J服务器状态,创建节点,填充节点属性,查询和创建关系。我的问题是我的“添加关系”和遍历代码需要一个节点URI作为输入。我可以查询节点并获取描述结果的正确JSON,但似乎无法获取URI位置。
这是我的getUserByEmail代码的简化版本:
public URI getUserByEmail( String email )
{
System.out.println( "GETTING USER BY EMAIL [" + email + "]..." );
String queryStr = "MATCH (user) WHERE user.nodetype=\'user\' and user.email=\'" + email + "\' RETURN user";
WebResource webResource = client.resource( ROOT_URI + "/transaction/commit" );
String payload = "{\"statements\" : [ {\"statement\" : \"" + queryStr + "\"} ]}";
ClientResponse response = webResource
.accept( MediaType.APPLICATION_JSON )
.type( MediaType.APPLICATION_JSON )
.entity( payload )
.post( ClientResponse.class );
String responseStr = response.getEntity( String.class );
URI responseLocation = response.getLocation();
System.out.println( "RESPONSE STRING: " + responseStr );
System.out.println( "GOT USER AT: [" + responseLocation + "]" );
return responseLocation;
}
JSON结果恢复正常,并反映了图数据库中的内容。但是,该位置始终为空。
只要我具有起始节点的URI,我正在使用的“添加关系”代码就可以正常工作。我拥有的代码基于住在这里的addRelationship()代码:
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句