Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Neo4j Cypher: Find exact match to array Node property in WHERE clause

Tags:

neo4j

cypher

Given a Neo4J Node with an array property, how do I create a Cypher query to return only the node(s) that match an array literal?

Using the console I created a node with the array property called "list":

neo4j-sh (0)$ create n = {list: [1,2,3]};
==> +-------------------+
==> | No data returned. |
==> +-------------------+
==> Nodes created: 1
==> Properties set: 1
==> 83 ms

neo4j-sh (0)$ start n=node(1) return n;
==> +-----------------------+
==> | n                     |
==> +-----------------------+
==> | Node[1]{list:[1,2,3]} |
==> +-----------------------+
==> 1 row
==> 1 ms

However, my query does not return the Node that was just created given a WHERE clause that matches an array literal:

neo4j-sh (0)$ start n=node(1) where n.list=[1,2,3] return n;
==> +---+
==> | n |
==> +---+
==> +---+
==> 0 row
==> 0 ms

It's entirely possible I'm mis-using Cypher. Any tips on doing exact array property matching in Cypher would be helpful.

like image 382
Rich Apodaca Avatar asked Aug 29 '12 05:08

Rich Apodaca


2 Answers

The console is always running the latest SNAPSHOT builds of Neoj4. the version refers to the Cypher Syntax parswer, we will point that out more clearly :)

Now, there has been some fixing around the Array handling in Cypher, see https://github.com/neo4j/community/pull/815 and https://github.com/neo4j/community/issues/818 which problably are the ones that make the console work. This has been merged in after 1.8.M07, so in order to get it work locally, please download one of the latest 1.8.-SNAPSHOT, build it from GITHUB or wait for 1.8.M08 which is due very soon.

/peter

like image 77
Peter Neubauer Avatar answered Sep 19 '22 09:09

Peter Neubauer


Which version of Neo4j are you using?

Your same code works for me in 1.8M07.

http://console.neo4j.org/?id=p9cy6l

Update: I get the same result (no results) in a local install via the web client. Maybe it's a web client issue?

like image 40
Eve Freeman Avatar answered Sep 19 '22 09:09

Eve Freeman