The default partition implementation is based on JDBM. By default it may already index some common attributes like objectClass and ou for example. However you really want to index attributes that your applications use frequently in canned queries.
Adding an index on an attribute is pretty simple. The configuration in the server.xml file needs to be altered before bulk loading data into the server. Otherwise your index will not work properly.
Indices must be configured before loading data into the server. Indices configured after loading entries into the server will NOT work properly unless they are built using the index builder command supplied with the ApacheDS tools command line program. More information on this in the Building Indices section below.
Indices are configured in the partition configuration section of your server.xml. Each partition will have it's own set of indexed attributes. These index configurations reside under the indexedAttributes property of the org.apache.directory.server.core.partition.impl.btree.MutableBTreePartitionConfiguration spring bean. Here's that section for the stock dc=example,dc=com partition that is configured out of the box with ApacheDS.
As you can see indices are specified using a MutableIndexConfiguration spring bean. Just add one of these to your existing configuration setting the attributeId to the OID or name of the attribute you want to index. There is cacheSize parameter used to set the amount of cache on your index as well. Most of the time 100 will suffice no matter how big in capacity your server is.
This number (100) is the number of entries stored in the cache, regardless to their size. Be carefull when dealing with huge entries - those which contains jpeg images -
So if I wanted to index the attribute initials all I have to do is append the following xml fragment to this set of indexed attributes: