18.8. Unique Indexes

18.8.1. Create a unique node in an index
18.8.2. Create a unique node in an index (the case where it exists)
18.8.3. Add a node to an index unless a node already exists for the given mapping
18.8.4. Create a unique relationship in an index
18.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”.

18.8.1. Create a unique node in an index

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

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

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

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

Figure 18.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": "Mattias", "uri":"http://localhost:7474/db/data/node/116"}

Example response

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

18.8.4. Create a unique relationship in an index

Figure 18.51. 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/67", "end": "http://localhost:7474/db/data/node/68", "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/67",
  "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/68"
}

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

Figure 18.52. 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/69",
  "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/70"
}