Prev |  | Next

## 20.21. Configurable Legacy Automatic Indexing

Out of the box auto-indexing supports exact matches since they are created with the default configuration (see Section 35.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 22.2, “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:

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

Example request

- `POST` `http://localhost:7474/db/data/index/node/`
- `Accept:` `application/json; charset=UTF-8`
- `Content-Type:` `application/json`

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

Example response

- `201:` `Created`
- `Content-Type:` `application/json; charset=UTF-8`
- `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:

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

Example request

- `POST` `http://localhost:7474/db/data/index/relationship/`
- `Accept:` `application/json; charset=UTF-8`
- `Content-Type:` `application/json`

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

Example response

- `201:` `Created`
- `Content-Type:` `application/json; charset=UTF-8`
- `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.

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

Example request

- `GET` `http://localhost:7474/db/data/index/auto/node/status`
- `Accept:` `application/json; charset=UTF-8`

Example response

- `200:` `OK`
- `Content-Type:` `application/json; charset=UTF-8`

    false

### 20.21.4. Enable node autoindexing

Example request

- `PUT` `http://localhost:7474/db/data/index/auto/node/status`
- `Accept:` `application/json; charset=UTF-8`
- `Content-Type:` `application/json`

    true

Example response

- `204:` `No Content`

### 20.21.5. Lookup list of properties being autoindexed

Example request

- `GET` `http://localhost:7474/db/data/index/auto/node/properties`
- `Accept:` `application/json; charset=UTF-8`

Example response

- `200:` `OK`
- `Content-Type:` `application/json; charset=UTF-8`

    [ "some-property" ]

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

Example request

- `POST` `http://localhost:7474/db/data/index/auto/node/properties`
- `Accept:` `application/json; charset=UTF-8`
- `Content-Type:` `application/json`

    myProperty1

Example response

- `204:` `No Content`

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

Example request

- `DELETE` `http://localhost:7474/db/data/index/auto/node/properties/myProperty1`
- `Accept:` `application/json; charset=UTF-8`

Example response

- `204:` `No Content`

Copyright © 2014 Neo Technology

Prev | Up | Next
| Home |