[[rest-api-configurable-auto-indexes]]
== Configurable Automatic Indexing ==

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

[source]
----
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 <<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:

include::create-an-auto-index-for-nodes-with-specific-configuration.txt[]

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

include::create-an-auto-index-for-relationships-with-specific-configuration.txt[]

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 http://components.neo4j.org/neo4j/{neo4j-version}/apidocs/org/neo4j/graphdb/index/AutoIndexer.html[AutoIndexer] component. The following REST calls work both, for `node` and `relationship` by simply changing the respective part of the URL.

include::get-current-status-for-autoindexing-on-nodes.txt[]

include::enable-node-autoindexing.txt[]

include::lookup-list-of-properties-being-autoindexed.txt[]

include::add-a-property-for-autoindexing-on-nodes.txt[]

include::remove-a-property-for-autoindexing-on-nodes.txt[]

