0
votes

This article is a follow-up to the question I posted earlier. The issue is that in neo4j 2.x docs, there is a note to the effect that constraints are recommended for creating or getting unique nodes:

As of Neo4j 2.0, unique constraints have been added. These make Neo4j enforce the uniqueness, guaranteeing that uniqueness is maintained. See the section called “Constraints” for details about this. For most cases, the unique constraints should be used rather than the features described below.

But in the Constraints sections of the neo4j docs, there is no explanation of how to invoke the REST API to create-or-get a unique node (unique on some label/property combination).

QUESTION: in neo4j 2.0, should I use uniqueness=get_or_create? If not, then what REST API endpoints are recommended for doing this?

1
I may have answered my own question. When you create a unique-constraint on a node-property, then neo4j automatically created a corresponding index for that node-property. At this point, I think you just use the REST API endpoints for get-or-create (ie, employing the uniqueness=get_or_create parameter in the queries).Kode Charlie

1 Answers

1
votes

Actually the unique constraints and schema indexes are created and maintained with Cypher.

(CREATE/DROP) INDEX ON :Label(property)

The application of the index/constraints happens automatically under the hood when running cypher queries.

MERGE is the get-or-create equivalent.

If you create or update a node with a duplicate property, that update will not happen and you receive an error.