Neo4j: results are duplicated
So I'm trying to find every Node that has at least a common Node with another one. This is the request I'm using to do this:
MATCH (source:Article)--(neighbor)--(target:Article) WHERE NOT (source.unique_url) = (target.unique_url) WITH DISTINCT [source.unique_url, target.unique_url] AS combo, source, target, neighbor RETURN combo, source.unique_url AS source_unique_url, source.title AS source_title, source.url AS source_url, target.unique_url AS target_unique_url, target._id AS target_id, target.title AS target_title, count(neighbor) AS common_neighbors ORDER BY common_neighbors DESCENDING
[source.unique_url, target.unique_url] is always duplicated, like for one Node having a common neighbour with another one, I always get results like this:
[url1, url2] [url2, url1] [url1, url2] [url2, url1]
I checked and the data is not duplicated in the DB, so the request is duplicating them, anyone knows what might be causing this ? Thanks a lot !
Use DISTINCT Key Word
i think you can use the DISTINCT with property after return keyword. try this. EX:-
return collect(distinct label) as lab
Try to change the start of your query like this.
- Add direction to relationships
- Add id(source) > id(target)
MATCH (source:Article)-->(neighbor<)--(target:Article) WHERE id(source) > id(target) WITH ...