speed up query

17 views
Skip to first unread message

Miguel Michelsongs

unread,
Jan 8, 2017, 11:14:38 PM1/8/17
to Neo4j
Hi all , 

I'm querying a graph trying to replicate the autocomplete feature from n4j admin, with the following cypher

MATCH p = (n:SomeLabel}{db_id:1})-[r*2..3]-(a)
                UNWIND nodes(p) as allnodes 
                WITH COLLECT(ID(allnodes)) AS ALLID 
                MATCH (a)-[r2]-(b) where ID(a) IN ALLID AND ID(b) IN ALLID 
                RETURN a as source , b as targets, r2 as rels
                LIMIT 170

if I increase the limit over 250 the query could take several minutes on my machine, is there a better approach doing only one query ?

best

Michael Hunger

unread,
Jan 9, 2017, 4:06:55 AM1/9/17
to ne...@googlegroups.com
Hey, what's your goal with this query?

You can try this:

MATCH p = (n:SomeLabel {db_id:1})-[r*2..3]-(a)
UNWIND nodes(p) as node
WITH COLLECT(distinct node) as nodes
UNWIND nodes as node
MATCH (node)-[r2]->(b) where b IN nodes
RETURN node as source , b as target, r2 as rel
LIMIT 170

alternatively you can try

MATCH p = (n:SomeLabel {db_id:1})-[r*2..3]-(a)
UNWIND nodes(p) as node
WITH COLLECT(distinct node) as nodes
UNWIND nodes as a
UNWIND nodes as b
MATCH (a)-[r2]->(b)
RETURN a as source , b as target, r2 as rel
LIMIT 170


--
You received this message because you are subscribed to the Google Groups "Neo4j" group.
To unsubscribe from this group and stop receiving emails from it, send an email to neo4j+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Miguel Michelsongs

unread,
Jan 9, 2017, 6:51:46 PM1/9/17
to ne...@googlegroups.com
Hi Michael , it works fine even increasing the limit
my goal was to replicate the autocomplete feature from neo4j admin

thank you very much for your help

best!

Atte.
Miguel Michelson Martinez
www.vadb.org

--
You received this message because you are subscribed to a topic in the Google Groups "Neo4j" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/neo4j/kwDJQHBtKEQ/unsubscribe.
To unsubscribe from this group and all its topics, send an email to neo4j+unsubscribe@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages