Neo4j Cypher pattern comprehension -
this neo4j sandbox query tests:
neo4j browser: https://10-0-1-223-34371.neo4jsandbox.com/ direct neo4j http: http://54.89.60.35:34371/browser/ username: neo4j password: capacities-complement-deputies ip address: 54.89.60.35 http port: 34371 bolt port: 34370
i have following cypher query:
match (parentd)<-[:defined_by]-(ch1:characteristic)<-[v1:has_value_on]-(childd) not (ch1)<-[:depends_on]-() , parentd.id = 1 return v1
which correctly returns following data(1 record):
{ "totalhistoryvalues": 0, "available": true, "description": "integer value 1", "value": 10 }
but inside of following query pattern comprehension:
match (parentd)-[:contains]->(childd:decision) parentd.id = 1 * match (childd)-[ru:created_by]->(u:user) optional match (childd)-[rup:updated_by]->(up:user) ru, u, rup, up, childd skip 0 limit 100 return ru, u, rup, up, childd decision, [ (parentd)<-[:defined_by]-(entity)<-[:commented_on]-(comg:commentgroup)-[:commented_for]->(childd) | {entityid: toint(entity.id), types: labels(entity), totalcomments: toint(comg.totalcomments)} ] commentgroups, [ (parentd)<-[:defined_by]-(c1)<-[vg1:has_vote_on]-(childd) | {criterionid: toint(c1.id), weight: vg1.avgvotesweight, totalvotes: toint(vg1.totalvotes)} ] weightedcriteria, [ (parentd)<-[:defined_by]-(ch1:characteristic)<-[v1:has_value_on]-(childd) not ((ch1)<-[:depends_on]-()) | {characteristicid: toint(ch1.id), value: v1.value, available: v1.available, totalhistoryvalues: v1.totalhistoryvalues, description: v1.description, valuetype: ch1.valuetype, visualmode: ch1.visualmode} ] valuedcharacteristics, [ (childd)-[rdt:belongs_to]->(t:tag) | t ] tags
valuedcharacteristics
accidentally contains 2 values:
{ "totalhistoryvalues": 0, "description": "integer value 2", "valuetype": "integer", "characteristicid": 2, "available": true, "visualmode": "integerrangeslider", "value": 20 } , { "totalhistoryvalues": 0, "description": "integer value 1", "valuetype": "integer", "characteristicid": 1, "available": true, "visualmode": "integerrangeslider", "value": 10 }
what wrong part of query:
[ (parentd)<-[:defined_by]-(ch1:characteristic)<-[v1:has_value_on]-(childd) not ((ch1)<-[:depends_on]-()) | {characteristicid: toint(ch1.id), value: v1.value, available: v1.available, totalhistoryvalues: v1.totalhistoryvalues, description: v1.description, valuetype: ch1.valuetype, visualmode: ch1.visualmode} ] valuedcharacteristics
and how fix in order return correct single record (because value#2 set characteristic parent(id=2)and should not present here)?
you should pass parentd
next context in with
. since you're not doing this, parentd
variable used on pattern comprehension not binded parentd.id = 1
. parentd
match
ing possible nodes. change query to:
match (parentd)-[:contains]->(childd:decision) parentd.id = 1 * match (childd)-[ru:created_by]->(u:user) optional match (childd)-[rup:updated_by]->(up:user) ru, u, rup, up, childd, parentd skip 0 limit 100 return ru, u, rup, up, childd decision, [ (parentd)<-[:defined_by]-(entity)<-[:commented_on]-(comg:commentgroup)-[:commented_for]->(childd) | {entityid: toint(entity.id), types: labels(entity), totalcomments: toint(comg.totalcomments)} ] commentgroups, [ (parentd)<-[:defined_by]-(c1)<-[vg1:has_vote_on]-(childd) | {criterionid: toint(c1.id), weight: vg1.avgvotesweight, totalvotes: toint(vg1.totalvotes)} ] weightedcriteria, [ (parentd)<-[:defined_by]-(ch1:characteristic)<-[v1:has_value_on]-(childd) not ((ch1)<-[:depends_on]-()) | {characteristicid: toint(ch1.id), value: v1.value, available: v1.available, totalhistoryvalues: v1.totalhistoryvalues, description: v1.description, valuetype: ch1.valuetype, visualmode: ch1.visualmode} ] valuedcharacteristics, [ (childd)-[rdt:belongs_to]->(t:tag) | t ] tags
wiki
Comments
Post a Comment