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

折月煮酒 提交于 2019-12-11 07:07:27

问题


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?


回答1:


You can do:

WHERE n.gender! = "M"

or

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


来源:https://stackoverflow.com/questions/19311926/how-to-cypher-query-a-neo4j-db-with-where-clause-on-sparse-property

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!