Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

querying with an "IN" clause using the index in neo4j with Cypher

Tags:

neo4j

I'd like to use my auto_index in neo4j and pass in an array of strings to match against. I know that you can add an IN clause to the end of your cypher query but that doesn't use the indexes and I'm assuming will do a database scan of all the records. What's the best way to do this with an index query?

e.g. Get me users whose facebookId is in ["123", "456", "789"] assuming there is an auto_index on facebookId and there are 1 million user nodes.

like image 639
MonkeyBonkey Avatar asked Nov 29 '12 20:11

MonkeyBonkey


People also ask

WHAT IS WITH clause in Cypher?

The WITH clause allows query parts to be chained together, piping the results from one to be used as starting points or criteria in the next. It is important to note that WITH affects variables in scope.

Which clause is used to search the data with a specified pattern in Neo4j?

The MATCH clause allows you to specify the patterns Neo4j will search for in the database.

Does Neo4j support indexing?

Neo4j will automatically pick up and start using the index once it has been created and brought online. There are multiple index types available: b-tree (deprecated), fulltext, lookup, and text index types.


2 Answers

I suppose this is worth posting as an answer:

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

Example: http://console.neo4j.org/r/3mcvr5

like image 72
Eve Freeman Avatar answered Oct 30 '22 19:10

Eve Freeman


You would do this query by having an explicit index lookup, like

start user = node:node_auto_index('facebookId:123 OR facebookId:456') match  ...

http://console.neo4j.org/r/nj98lt for an example.

like image 31
Peter Neubauer Avatar answered Oct 30 '22 20:10

Peter Neubauer