Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Uniqueness constraint and indexing issue

Tags:

neo4j

cypher

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?

like image 930
Steve P. Avatar asked Aug 07 '14 23:08

Steve P.


1 Answers

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."

like image 107
Luanne Avatar answered Sep 30 '22 04:09

Luanne