Houngan Houngan - 3 years ago 302
reST (reStructuredText) Question

How to use REDUCE with API REST Neo4j?

I want to use a Function REDUCE through a query with API REST of Neo4J. I tried :

:POST /db/data/cypher {
"query" :
"MATCH p=(n:SOL { PRB : {PRB}})-[r]-(m:SOL { PRB : {PRB2} })
RETURN DISTINCT nodes(p)" AS Experiences,
reduce(CONS=(1), r in relationships(p)|CONS*r.points) AS Impact,
"params" : {
"PRB" : "Beginning",
"PRB2" : "End"

As I used successfuly in Neo4j Browser, with adaptation for "params" according to API REST. But it doesn't work, I shall obtain : "Payload does not seem to be valid (JSON) data".

Answer Source

You have an extra " character in the 4th row, that's why the JSON does not get parsed. This should work:

:POST /db/data/cypher {
    "query": "MATCH p=(n:SOL { PRB : {PRB}})-[r]-(m:SOL { PRB : {PRB2} }) RETURN DISTINCT nodes(p) AS Experiences, reduce(CONS = (1), r in relationships(p) | CONS * r.points) AS Impact ",
    "params": {
        "PRB": "Beginning",
        "PRB2": "End"
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download