Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using neo4j auto index in Cypher WHERE filtering clause

Tags:

neo4j

cypher

Are auto-indices on (node or relationship) properties used by the Cypher execution engine when executing a filtering WHERE clause? If not, is there a way to tell Cypher to use them? What about for third-party (e.g., Lucene) indices?

like image 289
David B. Avatar asked Nov 30 '11 19:11

David B.


1 Answers

This is something that we've thought a lot about, but alas, not yet.

The indexing part of Neo4j is going to get an overhaul soon, and when that happens, we will tie Cypher closer to it, to be able to do this, and other interesting things (like heuristics to pick the right index to use).

You can do it manually though. If you have a movies<-[:ACTS_IN]-actor model, and you want all actor named Kevin Bacon that have participated in a movie, you can write it as:

START movie=node:movies("title:M*") 
MATCH movie<-[:ACTS_IN]-actor
WHERE actor.name = "Kevin Bacon"
RETURN movie.title

or, you can do the same with indexes:

START movie=node:movies("title:M*"),
      actor=node:actors(name="Kevin Bacon")
MATCH movie<-[:ACTS_IN]-actor
RETURN movie.title

Which one is the fastest is hard to tell. Depends.

like image 142
Andres Avatar answered Sep 30 '22 14:09

Andres