2014-11-24 68 views
0

我正在使用其余api在neo4j中的事务中创建一些节点。在创建所有节点之后(通常在一个事务中在3到5之间),我必须在它们之间建立一些关系。要做到这一点,我当然需要节点的位置,这是我的问题的根源。我无法弄清楚如何获得这个位置。java neo4j休息如何获得创建的节点的网址

根据文件,我应该能够得到从响应对象节点的位置,创造了节点,像这样经过:

nodeLocation = response.getLocation(); 

但在交易,这当然会返回交易网址:

http://localhost:7474/db/data/transaction/108 

然后我想,如果我查询刚创建的节点,也许在那个响应中我可以找到位置。同样,根据文档,节点位置应该显示在字段self的json结构扩展中。

"self" : "http://localhost:7474/db/data/node/357", 

但我对查询的回应似乎没有包含扩展结构。

这是我使用的查询:我把它发送到打开的事务

{"statements": [ {"statement": "MATCH (p:POST {sn_id: 'TW', id: '536982477664190465'}) RETURN p"} ] } 

,我得到这个回:

GET to http://localhost:7474/db/data/transaction/108 returned status code 200, returned data: {"commit":"http://localhost:7474/db/data/transaction/108/commit","results":[{"columns":["p"],"data":[]}],"transaction":{"expires":"Mon, 24 Nov 2014 20:40:34 +0000"},"errors":[]} 

只是为了保持完整性,这是代码我的查询:

String payload = "{\"statements\": " 
       + "[ " 
        + "{\"statement\": " 
         + "\"MATCH (p:POST {sn_id: 'TW', id: '536982477664190465'}) RETURN p\"" 
        + "} " 
       + "] " 
      + "}"; 


     logger.trace("sending cypher {} to endpoint {}", payload, endpointLoc); 
     WebResource resource = Client.create().resource(endpointLoc); 

     ClientResponse response = resource 
       .accept(MediaType.APPLICATION_JSON) 
       .type(MediaType.APPLICATION_JSON) 
       .entity(payload) 
       .get(ClientResponse.class); 
       //.post(ClientResponse.class); 

     String responseEntity = response.getEntity(String.class).toString(); 
     int responseStatus = response.getStatus(); 
     logger.trace("GET to {} returned status code {}, returned data: {}", 
       endpointLoc, responseStatus, 
       responseEntity); 

     JSONParser reponseParser = new JSONParser(); 
      Object responseObj = reponseParser.parse(responseEntity); 
      JSONObject jsonResponseObj = responseObj instanceof JSONObject ?(JSONObject) responseObj : null; 
      if(jsonResponseObj == null) 
       throw new ParseException(0, "returned json object is null"); 

      String result = (String) jsonResponseObj.get("results").toString(); 
      logger.trace("result is {} ", result); 

      String error = (String) jsonResponseObj.get("errors").toString(); 

我错过了什么吗?我需要使用特殊的电话吗?

有人可以帮助我吗?在此先感谢,

基督教

+0

您的MATCH查询返回无数据。也许这是因为数据库中没有任何匹配。此外,当您对getLocation()进行响应时,恐怕您可能会获取发布查询的位置的URL。这里的“响应”是从服务器返回的HTTP响应,而不是JSON响应负载。 – FrobberOfBits 2014-11-24 21:58:09

回答

0

你需要什么节点,网址?

这就是旧的 RESTful表示。您可以通过使用旧的HTTP端点/db/data/cypher或更好,通过指定(很详细)resultDataContents type REST 您也可以并行指定其他类型,如“行”和“图”。

{"statements": [ 
    {"statement": "MATCH (p:POST {sn_id: 'TW', id: '536982477664190465'}) RETURN p", 
    "resultDataContents":["REST"]} 
] } 
+0

完美。这正是我需要的 - 非常感谢 – siliconchris 2014-11-25 06:44:57