Neo4j Cypher manual relationship index, APOC trigger and data duplication

旧时模样 提交于 2019-12-24 09:52:29

问题


I have the following query that uses plain relationship operations for node filtering:

MATCH (dg:DecisionGroup)-[:CONTAINS]->(childD:Decision) 
WHERE dg.id = 1 
MATCH (childD)-[relationshipValueRel2:HAS_VALUE_ON]->(filterCharacteristic2:Characteristic) 
WHERE filterCharacteristic2.id = 2 
WITH relationshipValueRel2, childD, dg  
WHERE   (ANY (id IN [".NET"] WHERE id IN relationshipValueRel2.value ))  
RETURN childD.name

which returns only one node(as it was expected):

"Candidate1"

PROFILE output:

I'd like to optimize the query performance and this is why I use the following trigger in order to add the relationship into the manual index:

CALL apoc.trigger.add('HAS_VALUE_ON_ASSIGNED_RELATIONSHIP_PROPERTIES_TRIGGER', "UNWIND keys({assignedRelationshipProperties}) AS key 
UNWIND {assignedRelationshipProperties}[key] AS map 
WITH map 
WHERE type(map.relationship) = 'HAS_VALUE_ON' 
CALL apoc.index.addRelationship(map.relationship, keys(map.relationship))  RETURN true", 
{phase:'before'})

and the following query in order to get the same data as the first one but only from the manual index:

MATCH (dg:DecisionGroup)-[:CONTAINS]->(childD:Decision) 
WHERE dg.id = 1 
MATCH (childD)-[relationshipValueRel2:HAS_VALUE_ON]->(filterCharacteristic2:Characteristic) 
WHERE filterCharacteristic2.id = 2 
WITH relationshipValueRel2, filterCharacteristic2, childD, dg   
CALL apoc.index.in(filterCharacteristic2,'HAS_VALUE_ON','(value:(".NET"))') 
YIELD node WITH node AS childD 
RETURN childD.name

but the issue is, that this query returns two instances of the same node:

"Candidate1"
"Candidate1"

PROFILE output:

What am I doing wrong and why this query returns 2 instances instead of the single one ?

来源:https://stackoverflow.com/questions/50493806/neo4j-cypher-manual-relationship-index-apoc-trigger-and-data-duplication

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!