Prev |  | Next

## 18.10. Unique Indexes

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/15`

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

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

### 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/17"
    }

Example response

- `201:` `Created`
- `Content-Type:` `application/json`
- `Location:` `http://localhost:7474/db/data/index/node/people/name/Mattias/17`

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

### 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/280",
      "end" : "http://localhost:7474/db/data/node/281",
      "type" : "knowledge"
    }

Example response

- `201:` `Created`
- `Content-Type:` `application/json`
- `Location:` `http://localhost:7474/db/data/index/relationship/knowledge/name/Tobias/167`

    {
      "extensions" : {
      },
      "start" : "http://localhost:7474/db/data/node/280",
      "property" : "http://localhost:7474/db/data/relationship/167/properties/{key}",
      "self" : "http://localhost:7474/db/data/relationship/167",
      "properties" : "http://localhost:7474/db/data/relationship/167/properties",
      "type" : "knowledge",
      "end" : "http://localhost:7474/db/data/node/281",
      "data" : {
        "name" : "Tobias"
      },
      "indexed" : "http://localhost:7474/db/data/index/relationship/knowledge/name/Tobias/167"
    }

### 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/168"
    }

Example response

- `201:` `Created`
- `Content-Type:` `application/json`
- `Location:` `http://localhost:7474/db/data/index/relationship/knowledge/name/Mattias/168`

    {
      "extensions" : {
      },
      "start" : "http://localhost:7474/db/data/node/282",
      "property" : "http://localhost:7474/db/data/relationship/168/properties/{key}",
      "self" : "http://localhost:7474/db/data/relationship/168",
      "properties" : "http://localhost:7474/db/data/relationship/168/properties",
      "type" : "knowledge",
      "end" : "http://localhost:7474/db/data/node/283",
      "data" : {
      },
      "indexed" : "http://localhost:7474/db/data/index/relationship/knowledge/name/Mattias/168"
    }

Copyright © 2013 Neo Technology

Prev | Up | Next
| Home |