Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cypher: Extract unique values from collection

Tags:

neo4j

cypher

I have

MATCH (x)-[rels*]->(y)
RETURN extract( r in rels | r.property) as collected

where collected is a collection of properties of all relationships along the path, such as [null, 4, null, 4] or [1, 3, 3, 1].

How can I further extract from collected only its unique values? For example, [null, 4, null, 4] would change into [null, 4]

like image 480
Daniel Krizian Avatar asked Oct 29 '14 15:10

Daniel Krizian


People also ask

What is unwind in neo4j?

UNWIND expands a list into a sequence of rows.

How do you perform aggregation in Cypher?

The Cypher query offers aggregation similar to GROUP BY offered by SQL. The aggregate function can take multiple values and can calculate the aggregated values for them. In this recipe, we will learn the common aggregation techniques, with the help of examples.

How do I return all nodes and relationships in neo4j?

When you want to return all nodes, relationships and paths found in a query, you can use the * symbol. This returns the two nodes, the relationship and the path used in the query.

WHAT IS WITH clause in Cypher?

The WITH clause allows query parts to be chained together, piping the results from one to be used as starting points or criteria in the next. It is important to note that WITH affects variables in scope.


1 Answers

try this instead:

MATCH (x)-[rels*]->(y)
UNWIND rels AS rel
RETURN COLLECT( distinct rel.property) AS collected
like image 172
roman.ch Avatar answered Sep 26 '22 21:09

roman.ch