简体   繁体   中英

Cypher query via the REST endpoint : relationship not created

I'm using Neo4j 2.0.1 Community. I try to insert a relationship in the graph by sending the query through the REST endpoint.

My relationship query is very simple:

    MATCH (t1:Test { name : 'TEST_1' }), (t2:Test { name : 'TEST_2' }) CREATE (t1)-[:REL_TEST]->(t2)

I call it this way in Powershell:

    $postParams  = "{ `"query`" : `"MATCH (t1:Test { name : {test1} }), (t2:Test { name : {test2} }) CREATE (t1)-[:REL_TEST]->(t2)`",`"params`" : { `"test1`" : `"TEST_1`", `"test2`" : `"TEST_2`" } }"

    Invoke-WebRequest -Uri http://localhost:7474/db/data/cypher -Method POST -Body $postParams -Headers @{"Accept"="application/json; charset=UTF-8";"Content-Type"="application/json"}

And I got the following response:

    StatusCode        : 200
    StatusDescription : OK
    Content           : {
                          "columns" : [ ],
                          "data" : [ ]
                        }
    RawContent        : HTTP/1.1 200 OK
                Access-Control-Allow-Origin: *
                Content-Length: 40
                Content-Type: application/json; charset=UTF-8
                Server: Jetty(9.0.z-SNAPSHOT)

                {
                  "columns" : [ ],
                  "data" : [ ]
                }
    Forms             : {}
    Headers           : {[Access-Control-Allow-Origin, *], [Content-Length, 40], [Content-Type, application/json; charset=UTF-8], [Server, Jetty(9.0.z-SNAPSHOT)]}
    Images            : {}
    InputFields       : {}
    Links             : {}
    ParsedHtml        : mshtml.HTMLDocumentClass
    RawContentLength  : 40

But the relationship is not created. If I then type the same query in the browser UI, it works. I don't get what I'm an doing wrong, especially since the query works in the browser and the REST calling procedure works for inserting a node for example.

Are you certain that your query is not working. You are not returning any data so it's possible it is being created without your knowing it.

You could try something like this

MATCH (t1:Test{name: {test1}}), (t2:Test{name: {test2}})
CREATE (t1)-[rel:REL_TEST]->(t2)
RETURN rel

If you don't get the rel in your response it means the rel wasn't created probably because at least one of the MATCH es failed. Try returning t1 and t2 as well to see if they are working as expected.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM