简体   繁体   中英

Create a property index for all nodes in Cypher

I have 1 rule for my database. EVERYTHING must have an 'id'. Since this is my primary key field, I want to index it, but it seems the only way to create an index is to specify a label.

So with this dataset

CREATE (:TEST1{id:"<uuid>"}),
(:RAWR{id:"<uuid>"}),
(:FOO:BAR{id:"<uuid>"}),
({id:"<uuid>"})

I would like to use an index to find the unlabeled node by its UUID.

Is this possible in Cypher? Or is my ONLY option to inject a 'node' label onto EVERYTHING entering the database? (It feels wrong to create a label and then assign it to everything. And to hijack all create requests to add that additional label feels like I'm asking for trouble.)

A node can have multiple labels. So, in addition to your existing labels, you could assign a common label to all your nodes and then create an index using that common label and id .

However, since you intend the id value to be globally unique, instead of creating an index you should create a uniqueness constraint (which automatically creates an index for you as a side effect). That would tell neo4j to enforce id uniqueness for you.

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