Prev |  | Next

## 18.12. Configurable Automatic Indexing

Out of the box auto-indexing supports exact matches since they are created with the default configuration (see Section 14.12, “Automatic Indexing”) the first time you access them. However it is possible to intervene in the lifecycle of the server before any auto indexes are created to change their configuration.

| Warning
This approach cannot be used on databases that already have auto-indexes established. To change the auto-index configuration existing indexes would have to be deleted first, so be careful!

| Caution
This technique works, but it is not particularly pleasant. Future versions of Neo4j may remove this loophole in favour of a better structured feature for managing auto-indexing configurations.

Auto-indexing must be enabled through configuration before we can create or configure them. Firstly ensure that you’ve added some config like this into your server’s `neo4j.properties` file:

    node_auto_indexing=true
    relationship_auto_indexing=true
    node_keys_indexable=name,phone
    relationship_keys_indexable=since

The `node_auto_indexing` and `relationship_auto_indexing` settings turn auto-indexing on for nodes and relationships respectively. The `node_keys_indexable` key allows you to specify a comma-separated list of node property keys to be indexed. The `relationship_keys_indexable` does the same for relationship property keys.

Next start the server as usual by invoking the start script as described in Section 17.1, “Server Installation”.

Next we have to pre-empt the creation of an auto-index, by telling the server to create an apparently manual index which has the same name as the node (or relationship) auto-index. For example, in this case we’ll create a node auto index whose name is `node_auto_index`, like so:

### 18.12.1. Create an auto index for nodes with specific configuration

Example request

- `POST` `http://localhost:7474/db/data/index/node/`
- `Accept:` `application/json`
- `Content-Type:` `application/json`

    {
      "name" : "node_auto_index",
      "config" : {
        "type" : "fulltext",
        "provider" : "lucene"
      }
    }

Example response

- `201:` `Created`
- `Content-Type:` `application/json`
- `Location:` `http://localhost:7474/db/data/index/node/node_auto_index/`

    {
      "template" : "http://localhost:7474/db/data/index/node/node_auto_index/{key}/{value}",
      "type" : "fulltext",
      "provider" : "lucene"
    }

If you require configured auto-indexes for relationships, the approach is similar:

### 18.12.2. Create an auto index for relationships with specific configuration

Example request

- `POST` `http://localhost:7474/db/data/index/relationship/`
- `Accept:` `application/json`
- `Content-Type:` `application/json`

    {
      "name" : "relationship_auto_index",
      "config" : {
        "type" : "fulltext",
        "provider" : "lucene"
      }
    }

Example response

- `201:` `Created`
- `Content-Type:` `application/json`
- `Location:` `http://localhost:7474/db/data/index/relationship/relationship_auto_index/`

    {
      "template" : "http://localhost:7474/db/data/index/relationship/relationship_auto_index/{key}/{value}",
      "type" : "fulltext",
      "provider" : "lucene"
    }

In case you’re curious how this works, on the server side it triggers the creation of an index which happens to have the same name as the auto index that the database would create for itself. Now when we interact with the database, the index thinks the index is already created so the state machine skips over that step and just gets on with normal day-to-day auto-indexing.

| Caution
You have to do this early in your server lifecycle, before any normal auto indexes are created.

There are a few REST calls providing a REST interface to the AutoIndexer component. The following REST calls work both, for `node` and `relationship` by simply changing the respective part of the URL.

### 18.12.3. Get current status for autoindexing on nodes

Figure 18.64. Final Graph

Example request

- `GET` `http://localhost:7474/db/data/index/auto/node/status`
- `Accept:` `application/json`

Example response

- `200:` `OK`
- `Content-Type:` `application/json`

    false

### 18.12.4. Enable node autoindexing

Figure 18.65. Final Graph

Example request

- `PUT` `http://localhost:7474/db/data/index/auto/node/status`
- `Accept:` `application/json`
- `Content-Type:` `application/json`

    true

Example response

- `204:` `No Content`

### 18.12.5. Lookup list of properties being autoindexed

Figure 18.66. Final Graph

Example request

- `GET` `http://localhost:7474/db/data/index/auto/node/properties`
- `Accept:` `application/json`

Example response

- `200:` `OK`
- `Content-Type:` `application/json`

    [ "some-property" ]

### 18.12.6. Add a property for autoindexing on nodes

Figure 18.67. Final Graph

Example request

- `POST` `http://localhost:7474/db/data/index/auto/node/properties`
- `Accept:` `application/json`
- `Content-Type:` `application/json`

    myProperty1

Example response

- `204:` `No Content`

### 18.12.7. Remove a property for autoindexing on nodes

Figure 18.68. Final Graph

Example request

- `DELETE` `http://localhost:7474/db/data/index/auto/node/properties/myProperty1`
- `Accept:` `application/json`

Example response

- `204:` `No Content`

Copyright © 2013 Neo Technology

Prev | Up | Next
| Home |