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/163
{
  "indexed" : "http://localhost:7474/db/data/index/node/people/name/Tobias/163",
  "outgoing_relationships" : "http://localhost:7474/db/data/node/163/relationships/out",
  "data" : {
    "sequence" : 1,
    "name" : "Tobias"
  },
  "traverse" : "http://localhost:7474/db/data/node/163/traverse/{returnType}",
  "all_typed_relationships" : "http://localhost:7474/db/data/node/163/relationships/all/{-list|&|types}",
  "property" : "http://localhost:7474/db/data/node/163/properties/{key}",
  "self" : "http://localhost:7474/db/data/node/163",
  "outgoing_typed_relationships" : "http://localhost:7474/db/data/node/163/relationships/out/{-list|&|types}",
  "properties" : "http://localhost:7474/db/data/node/163/properties",
  "incoming_relationships" : "http://localhost:7474/db/data/node/163/relationships/in",
  "extensions" : {
  },
  "create_relationship" : "http://localhost:7474/db/data/node/163/relationships",
  "paged_traverse" : "http://localhost:7474/db/data/node/163/paged/traverse/{returnType}{?pageSize,leaseTime}",
  "all_relationships" : "http://localhost:7474/db/data/node/163/relationships/all",
  "incoming_typed_relationships" : "http://localhost:7474/db/data/node/163/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/164",
  "outgoing_relationships" : "http://localhost:7474/db/data/node/164/relationships/out",
  "data" : {
    "sequence" : 1,
    "name" : "Peter"
  },
  "traverse" : "http://localhost:7474/db/data/node/164/traverse/{returnType}",
  "all_typed_relationships" : "http://localhost:7474/db/data/node/164/relationships/all/{-list|&|types}",
  "property" : "http://localhost:7474/db/data/node/164/properties/{key}",
  "self" : "http://localhost:7474/db/data/node/164",
  "outgoing_typed_relationships" : "http://localhost:7474/db/data/node/164/relationships/out/{-list|&|types}",
  "properties" : "http://localhost:7474/db/data/node/164/properties",
  "incoming_relationships" : "http://localhost:7474/db/data/node/164/relationships/in",
  "extensions" : {
  },
  "create_relationship" : "http://localhost:7474/db/data/node/164/relationships",
  "paged_traverse" : "http://localhost:7474/db/data/node/164/paged/traverse/{returnType}{?pageSize,leaseTime}",
  "all_relationships" : "http://localhost:7474/db/data/node/164/relationships/all",
  "incoming_typed_relationships" : "http://localhost:7474/db/data/node/164/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/165"}

Example response

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

Example response

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

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/91"}

Example response

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