I can't get Neo4j to add a unique relationship. I'm using neo4j 2.0.0.M6 and REST API.
I use this url: /db/data/index/relationship/rels?uniqueness=get_or_create, and I keep getting "bad request" all the time. I follow this API guide.
What do I do wrong? Should I pass in the index name or relationship key? I send json with 3 keys in it - "start", "end", "type". Error message says that I'm missing required keys: [value, key] - what should I put there?
1 Answers
I understand your confusion.
This api endpoint is doing two things. 1. It is creating a relationship. 2. It is adding it to an index if it doesn't exist already
And index has a Name, a Key, and a Value.
So if I have an index named "People" I might want to index on "Name" and "DateOfBirth" which are keys. The values could be "LameCoder" and "11/11/2013" respectively.
The URL you're using is implicitly saying the name of the index is "rels" because that's what that part of the URL is for.
This is the example from the documentation. Key and Value are basically what will be added to the index. They don't necessarily have to exist in the property map of the relationship. So in this case below the key is name and the value is Peter. So it's going to insure that no other index entry for Key "name" with value "Peter" exists in index "rels" when creating the relationship.
{
"key" : "name",
"value" : "Peter",
"start" : "http://localhost:7474/db/data/node/444",
"end" : "http://localhost:7474/db/data/node/445",
"type" : "KNOWS"
}
This is not creating a unique relationship between those two nodes. It's a unique relationship across the index. So if you are expecting this to ensure that only one relationship of a type exists between two nodes, this is not what you want.