MonkeyBonkey
MonkeyBonkey

Reputation: 47861

match in clause in cypher

How can I do an match in clause in cypher

e.g. I'd like to find movies with ids 1, 2, or 3.

match (m:movie {movie_id:("1","2","3")}) return m

if you were going against an auto index the syntax was

START n=node:node_auto_index('movie_id:("123", "456", "789")')

how is this different against a match clause

Upvotes: 4

Views: 6716

Answers (2)

Damon Horrell
Damon Horrell

Reputation: 2264

I've found a (somewhat ugly) temporary workaround for this.

The following query doesn't make use of an index on Person(name):

match (p:Person)... where p.name in ['JOHN', 'BOB'] return ...;

So one option is to repeat the entire query n times:

match (p:Person)... where p.name = 'JOHN' return ...
union
match (p:Person)... where p.name = 'BOB' return ...

If this is undesirable then another option is to repeat just a small query for the id n times:

match (p:Person) where p.name ='JOHN' return id(p)
union
match (p:Person) where p.name ='BOB' return id(p);

and then perform a second query using the results of the first:

match (p:Person)... where id(p) in [8,16,75,7] return ...;

Is there a way to combine these into a single query? Can a union be nested inside another query?

Upvotes: 0

Eve Freeman
Eve Freeman

Reputation: 33145

The idea is that you can do:

MATCH (m:movie)
WHERE m.movie_id in ["1", "2", "3"]

However, this will not use the index as of 2.0.1. This is a missing feature in the new label indexes that I hope will be resolved soon. https://github.com/neo4j/neo4j/issues/861

Upvotes: 7

Related Questions