java neo4j如何获取已创建节点的url

时间:2014-11-24 21:01:38

标签: java rest neo4j

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

根据文档,我应该能够在创建节点后从response-object获取节点的位置,如下所示:

nodeLocation = response.getLocation();

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

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

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

 "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();

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

有人可以帮我吗?提前谢谢,

基督教

1 个答案:

答案 0 :(得分:0)

您需要什么节点网址?

这是旧的 RESTful表示。您可以通过使用旧的HTTP端点/db/data/cypher或更好地通过指定(非常详细)resultDataContents type REST来获取它 您还可以并行指定其他类型,如“行”和“图形”。

 {"statements": [ 
   {"statement": "MATCH (p:POST {sn_id: 'TW', id: '536982477664190465'} ) RETURN p",
    "resultDataContents":["REST"]} 
 ] }
相关问题