Head's Up! These forums are read-only. All users and content have migrated. Please join us at community.neo4j.com.
07-26-2020 12:15 PM
Hi all,
I am quite new to Neo4j and cypher queries and it would be great if you could help me.
I have the following nodes:
Transaction (tx)
Output (output)
with the following relations:
Incoming (in)
Outgoing (out)
a Transaction creates 1-n outputs which can be used as inputs for other transactions.
I want to check, which outputs and transactions are children of a target transaction (means, created inputs for the target transaction.) This query checks 2 hops back:
MATCH path= (roottx:tx {txid:'266160772'})<-[:in|:out]-(output0:output)<-[:in|:out]-(subtx:tx)<-[:in|:out]-(output1:output)<-[:in|:out]-(subtx1:tx)<-[:in|:out]-(output2:output)
RETURN path
I have the aim, that the query should be flexible - means it should be able to check more hops back.
I think there is definitely a better way than extending the query.
I already had a look in APOC methods - but I was not able to find the right one.
Thanks a Lot for your help and your time!
07-26-2020 12:21 PM
Hello @peetsees and welcome to the Ne4j community
You should have a look at this:
https://neo4j.com/docs/cypher-manual/current/clauses/match/#varlength-rels
Regards,
Cobra
07-26-2020 12:31 PM
@Cobra: Thanks a lot! I had a look in this chapter, but somehow I was not able to handle the outputs and transactions....
Now I managed it!
MATCH path= (roottx:tx {txid:'266160772'})<-[:in|:out*1..6]-(tx:tx)
RETURN path
basically delivered the same result as my query in the original post above!
Thanks for your help!
07-26-2020 12:34 PM
Nice, I'm happy to hear this
07-26-2020 04:21 PM
On additional idea came to my mind, which I am trying to find a query:
It would be great to see the interactions of transactions. Means, I would like to see only transactions in my graph, without he outputs of the transactions (see picture above).
I tried to formulate the query like this:
MATCH (roottx:tx {txid:'266160772'})<-[:in|:out*1..6]-(tx:tx)
RETURN tx
But then the relationsships are gone:
Is it possible, to replace the OUTPUT nodes, but still create a connection between the TRANSACTION nodes?
Thanks for your help!
07-31-2020 04:48 AM
You can simply return only the nodes that you want:
MATCH path= (roottx:tx {txid:'266160772'})<-[:in|:out*1..6]-(tx:tx)
RETURN tx
07-26-2020 11:34 PM
Your orange nodes are not directly connected to each other right? There are blue node between them?
07-27-2020 01:11 PM
Yes.
Transactions (orange nodes) are connected with outputs (blue nodes) via IN or OUT relation.
So, I would need to replace the IN-OUTPUT-OUT part between the transactions with a kind of dummy relation (only in the query result).
07-27-2020 02:00 PM
You will have to create this "dummy" relation if you want to display it
All the sessions of the conference are now available online