I must be doing something incorrectly, or have a misconceptions about constraints and indexing. I have the following:
CREATE CONSTRAINT ON (u:User) ASSERT u.user_id IS UNIQUE
and
CREATE INDEX ON :User(user_id)
I've tried alternating the order, but regardless, I'm getting:
Neo.ClientError.Schema.ConstraintAlreadyExists
or
Neo.ClientError.Schema.IndexAlreadyExists
depending on the ordering.
I don't understand why I wouldn't be able to do this. I want look-ups to be fast for a user_id
, which is why I'm indexing, and I also want to make sure that user_id
is unique, which is why I have a constraint.
What am I misunderstanding? How should I go about doing this?
Adding the unique constraint will also add the index on that property- so the unique constraint is sufficient.
See http://docs.neo4j.org/chunked/stable/query-constraints.html
"Note that adding a uniqueness constraint on a property will also add an index on that property, so you cannot add such an index separately. Cypher will use that index for lookups just like other indexes. If you drop a constraint and still want an index on the property, you will have to create the index."
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With