1

I am trying to find all the children of a particular node.

match(t:TAG)<-[children:CHILD_OF]-(subtag:TAG) where t.name="brand" return t.name, subtag.name

I am getting the correct result from the query above. But I am doubtful that this query is efficient. As it is first getting all the relationships of "tagA is a child of tagB" and then filtering it where tagB is as given.

There must be a better way to write this. Please help.

tanvi
  • 927
  • 5
  • 17
  • 32

1 Answers1

3

Try this

match(t:TAG) where t.name="brand" with t 
Match (t)<-[children:CHILD_OF]-(subtag:TAG)  return t.name, subtag.name

You can check the difference by using profile

Evgen
  • 1,278
  • 3
  • 13
  • 25
  • surprisingly my query is faster – tanvi Apr 04 '16 at 08:10
  • It might be becouse of your data set (you have small number of tags and neo4j optimizes query), cache. And if not it seems strange to me, make sure you have index on name. – Evgen Apr 04 '16 at 08:22
  • That could be the case. How can I check that I have an index? – tanvi Apr 04 '16 at 08:34
  • 1
    Look here for index info http://stackoverflow.com/questions/19801599/neo4j-is-there-a-cypher-query-syntax-to-list-show-all-indexes-in-db – Evgen Apr 04 '16 at 08:37