Jaap
Jaap

Reputation: 89

Create a query which only returns a subset of the entire graph in Cypher

I've a data set of historical people that were connected to events (e.g. baptisms or marriages) or sources (e.g. wills), which are in turn connected to other people and the particular Church in which the event took place. I can create an overview of the immediate network of a given person via this query:

MATCH (p:person {ID: 'TRE_person_0281'})-[r*1..**2**]-(n) RETURN p, r, n

This returns the following outcome:Query result

Ideally, I would like to see the slightly wider network, namely the other events/sources these people are connected to as well (and the people and churches connected to these events/sources, too). However, using the following query creates a huge graph since it shows all the events connected to the churches (which were many):

MATCH (p:person {ID: 'TRE_person_0281'})-[r*1..**3**]-(n) RETURN p, r, n

So my question is how to construct a query which shows the nodes connected to the events to which the people were connected who were directly connected to events to which person 'TRE_person_0281' was connected.

Upvotes: 0

Views: 31

Answers (1)

cybersam
cybersam

Reputation: 66999

This shows one of the beauties of using a graph DB with Cypher.

Your phrase, "the nodes connected to the events to which the people were connected who were directly connected to events to which person 'TRE_person_0281' was connected" is easily converted into the equivalent Cypher query:

MATCH p = ()--(:event)--(:person)--(:event)--(:person {ID: 'TRE_person_0281'})
RETURN p

Upvotes: 0

Related Questions