简体   繁体   中英

How to cypher query a neo4j DB with WHERE clause on sparse property

I have Nodes in my Neo4j database that have certain properties that do not exist on all nodes, but I want to query against those properties with Cypher with a WHERE clause.

Example Data:

{id:"52", name:"Jim", age:"32", gender:"M"}
{id:"55", name:"Lisa", age:"22", gender:"F"}
{id:"97", name:"Chris", age:"38"}

Now, if I want to run a Cypher query on gender, it gives me an error on the Chris record, stating that the gender property does not exist on that node.

Example Cypher query:

START n=NODE(*) WHERE n.gender="M" RETURN n;

The specific error message I am getting is:

EntityNotFoundException: The property 'gender' does not exist on Node[4925]

I am running version 1.9.2 of Neo4j. I'd like to upgrade to 2.x and try to use labels and auto_indexes galore. But, I'm not in a position go move away from the stable release yet.

Any way to solve this with Cypher query, or with 1.9.2 indexing features?

You can do:

WHERE n.gender! = "M"

or

WHERE has(n.gender) AND n.gender = "M"

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