2014-11-24 67 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