简体   繁体   中英

match in clause in cypher

How can I do an match in clause in cypher

eg 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

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

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?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM