cancel
Showing results for 
Search instead for 
Did you mean: 

Head's Up! These forums are read-only. All users and content have migrated. Please join us at community.neo4j.com.

Cypher Merge without Merging

Hi all,

Sorry if this has been answered. It's hard to know what to search for when you don't know what you don't know. Seems like a basic question, but I can't find an answer.

I have a db with ~10000 nodes... author nodes and book nodes. Authors have a country property. I can run a match that shows the full network of authors, books and connections to coauthors etc. So I can kind of see which authors have worked with which author authors.

What I want to do is show a network where I have countries that have worked with other countries. I.e if 10 authors from the USA have coauthored a book with 3 authors from the UK and 5 from India, say, I want to show that as 3 country nodes in Neo4J with a count of books on the edge.

I kind of managed to do this using APOC merge... but then the merge is permanent so all my author nodes get merged, rather than it just being a temporary view.

Is this possible to do? Can write a query that will aggregate my data into a graph of country nodes without permanently merging my authors.?

Thanks

2 REPLIES 2

Typical. Spend a week looking for answers, doing every search term I can think of, finally give up and ask the community... then find the answer an hour later.

For anyone else looking to do this, the answer seems to be Virtual Nodes.

Hi @gary.frewin

If I'm right the question you want to ask to your database is:

Give me all the sets of country who worked together to create one or more books, it's true that the answer is not obvious with your actual architecture but still it's easily possible to get it.

MATCH (a:Author)-[:WRITE]->(b)
WITH collect(DISTINCT a.country) AS countries, b AS book
RETURN countries, count(book) AS books

This should do it without virtual nodes and mostly without relying on advanced stuff like apoc, but you will get your answer as tables. If you want it as a graph indeed you need virtual nodes.