18.10. Unique Indexes

18.10.1. Create a unique node in an index
18.10.2. Create a unique node in an index (the case where it exists)
18.10.3. Add a node to an index unless a node already exists for the given mapping
18.10.4. Create a unique relationship in an index
18.10.5. Add a relationship to an index unless a relationship already exists for the given mapping

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

18.10.1. Create a unique node in an index

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

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

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

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

Figure 18.59. 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/182"
}

Example response

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

18.10.4. Create a unique relationship in an index

Figure 18.60. 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
{
  "extensions" : {
  },
  "start" : "http://localhost:7474/db/data/node/80",
  "property" : "http://localhost:7474/db/data/relationship/90/properties/{key}",
  "self" : "http://localhost:7474/db/data/relationship/90",
  "properties" : "http://localhost:7474/db/data/relationship/90/properties",
  "type" : "knowledge",
  "end" : "http://localhost:7474/db/data/node/81",
  "data" : {
    "name" : "Tobias"
  },
  "indexed" : "http://localhost:7474/db/data/index/relationship/knowledge/name/Tobias/90"
}

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

Figure 18.61. 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
{
  "extensions" : {
  },
  "start" : "http://localhost:7474/db/data/node/82",
  "property" : "http://localhost:7474/db/data/relationship/91/properties/{key}",
  "self" : "http://localhost:7474/db/data/relationship/91",
  "properties" : "http://localhost:7474/db/data/relationship/91/properties",
  "type" : "knowledge",
  "end" : "http://localhost:7474/db/data/node/83",
  "data" : {
  },
  "indexed" : "http://localhost:7474/db/data/index/relationship/knowledge/name/Mattias/91"
}