19.8. Unique Indexes

19.8.1. Create a unique node in an index
19.8.2. Create a unique node in an index (the case where it exists)
19.8.3. Add a node to an index unless a node already exists for the given mapping
19.8.4. Create a unique relationship in an index
19.8.5. Add a relationship to an index unless a relationship already exists for the given mapping

For more information, see Section 13.6, “Creating unique nodes”.

19.8.1. Create a unique node in an index

Figure 19.50. Final Graph


Example request

  • POST http://localhost:7474/db/data/index/node/people?unique
  • Accept: application/json
  • Content-Type: application/json
{"key": "name", "value": "Tobias", "properties": {"name": "Tobias", "sequence": 1}}

Example response

  • 201: Created
  • Content-Type: application/json
  • Location: http://localhost:7474/db/data/index/node/people/name/Tobias/119
{
  "indexed" : "http://localhost:7474/db/data/index/node/people/name/Tobias/119",
  "outgoing_relationships" : "http://localhost:7474/db/data/node/119/relationships/out",
  "data" : {
    "sequence" : 1,
    "name" : "Tobias"
  },
  "traverse" : "http://localhost:7474/db/data/node/119/traverse/{returnType}",
  "all_typed_relationships" : "http://localhost:7474/db/data/node/119/relationships/all/{-list|&|types}",
  "property" : "http://localhost:7474/db/data/node/119/properties/{key}",
  "self" : "http://localhost:7474/db/data/node/119",
  "outgoing_typed_relationships" : "http://localhost:7474/db/data/node/119/relationships/out/{-list|&|types}",
  "properties" : "http://localhost:7474/db/data/node/119/properties",
  "incoming_relationships" : "http://localhost:7474/db/data/node/119/relationships/in",
  "extensions" : {
  },
  "create_relationship" : "http://localhost:7474/db/data/node/119/relationships",
  "paged_traverse" : "http://localhost:7474/db/data/node/119/paged/traverse/{returnType}{?pageSize,leaseTime}",
  "all_relationships" : "http://localhost:7474/db/data/node/119/relationships/all",
  "incoming_typed_relationships" : "http://localhost:7474/db/data/node/119/relationships/in/{-list|&|types}"
}

19.8.2. Create a unique node in an index (the case where it exists)

Figure 19.51. Final Graph


Example request

  • POST http://localhost:7474/db/data/index/node/people?unique
  • Accept: application/json
  • Content-Type: application/json
{"key": "name", "value": "Peter", "properties": {"name": "Peter", "sequence": 2}}

Example response

  • 200: OK
  • Content-Type: application/json
{
  "indexed" : "http://localhost:7474/db/data/index/node/people/name/Peter/120",
  "outgoing_relationships" : "http://localhost:7474/db/data/node/120/relationships/out",
  "data" : {
    "sequence" : 1,
    "name" : "Peter"
  },
  "traverse" : "http://localhost:7474/db/data/node/120/traverse/{returnType}",
  "all_typed_relationships" : "http://localhost:7474/db/data/node/120/relationships/all/{-list|&|types}",
  "property" : "http://localhost:7474/db/data/node/120/properties/{key}",
  "self" : "http://localhost:7474/db/data/node/120",
  "outgoing_typed_relationships" : "http://localhost:7474/db/data/node/120/relationships/out/{-list|&|types}",
  "properties" : "http://localhost:7474/db/data/node/120/properties",
  "incoming_relationships" : "http://localhost:7474/db/data/node/120/relationships/in",
  "extensions" : {
  },
  "create_relationship" : "http://localhost:7474/db/data/node/120/relationships",
  "paged_traverse" : "http://localhost:7474/db/data/node/120/paged/traverse/{returnType}{?pageSize,leaseTime}",
  "all_relationships" : "http://localhost:7474/db/data/node/120/relationships/all",
  "incoming_typed_relationships" : "http://localhost:7474/db/data/node/120/relationships/in/{-list|&|types}"
}

19.8.3. Add a node to an index unless a node already exists for the given mapping

Figure 19.52. Final Graph


Example request

  • POST http://localhost:7474/db/data/index/node/people?unique
  • Accept: application/json
  • Content-Type: application/json
{"key": "name", "value": "Mattias", "uri":"http://localhost:7474/db/data/node/121"}

Example response

  • 201: Created
  • Content-Type: application/json
  • Location: http://localhost:7474/db/data/index/node/people/name/Mattias/121
{
  "indexed" : "http://localhost:7474/db/data/index/node/people/name/Mattias/121",
  "outgoing_relationships" : "http://localhost:7474/db/data/node/121/relationships/out",
  "data" : {
  },
  "traverse" : "http://localhost:7474/db/data/node/121/traverse/{returnType}",
  "all_typed_relationships" : "http://localhost:7474/db/data/node/121/relationships/all/{-list|&|types}",
  "property" : "http://localhost:7474/db/data/node/121/properties/{key}",
  "self" : "http://localhost:7474/db/data/node/121",
  "outgoing_typed_relationships" : "http://localhost:7474/db/data/node/121/relationships/out/{-list|&|types}",
  "properties" : "http://localhost:7474/db/data/node/121/properties",
  "incoming_relationships" : "http://localhost:7474/db/data/node/121/relationships/in",
  "extensions" : {
  },
  "create_relationship" : "http://localhost:7474/db/data/node/121/relationships",
  "paged_traverse" : "http://localhost:7474/db/data/node/121/paged/traverse/{returnType}{?pageSize,leaseTime}",
  "all_relationships" : "http://localhost:7474/db/data/node/121/relationships/all",
  "incoming_typed_relationships" : "http://localhost:7474/db/data/node/121/relationships/in/{-list|&|types}"
}

19.8.4. Create a unique relationship in an index

Figure 19.53. Final Graph


Example request

  • POST http://localhost:7474/db/data/index/relationship/knowledge/?unique
  • Accept: application/json
  • Content-Type: application/json
{"key": "name", "value":"Tobias", "start": "http://localhost:7474/db/data/node/68", "end": "http://localhost:7474/db/data/node/69", "type": "knowledge"}

Example response

  • 201: Created
  • Content-Type: application/json
  • Location: http://localhost:7474/db/data/index/relationship/knowledge/name/Tobias/23
{
  "indexed" : "http://localhost:7474/db/data/index/relationship/knowledge/name/Tobias/23",
  "start" : "http://localhost:7474/db/data/node/68",
  "data" : {
    "name" : "Tobias"
  },
  "self" : "http://localhost:7474/db/data/relationship/23",
  "property" : "http://localhost:7474/db/data/relationship/23/properties/{key}",
  "properties" : "http://localhost:7474/db/data/relationship/23/properties",
  "type" : "knowledge",
  "extensions" : {
  },
  "end" : "http://localhost:7474/db/data/node/69"
}

19.8.5. Add a relationship to an index unless a relationship already exists for the given mapping

Figure 19.54. Final Graph


Example request

  • POST http://localhost:7474/db/data/index/relationship/knowledge/?unique
  • Accept: application/json
  • Content-Type: application/json
{"key": "name", "value":"Mattias", "uri": "http://localhost:7474/db/data/relationship/24"}

Example response

  • 201: Created
  • Content-Type: application/json
  • Location: http://localhost:7474/db/data/index/relationship/knowledge/name/Mattias/24
{
  "indexed" : "http://localhost:7474/db/data/index/relationship/knowledge/name/Mattias/24",
  "start" : "http://localhost:7474/db/data/node/70",
  "data" : {
  },
  "self" : "http://localhost:7474/db/data/relationship/24",
  "property" : "http://localhost:7474/db/data/relationship/24/properties/{key}",
  "properties" : "http://localhost:7474/db/data/relationship/24/properties",
  "type" : "knowledge",
  "extensions" : {
  },
  "end" : "http://localhost:7474/db/data/node/71"
}