Most of the data stored in Solr has some kind of primary key. Primary keys are different from most of the fields in your data as each document has a unique value stored; because they are primary in most cases they are unique. Because of that, a search on this primary field is not always as fast as you would expect when you compare it to databases. So, is there anything we can do to make it faster? With Solr 4.0 we can, and this recipe will show you how to improve the execution time of queries run against unique fields in Solr.
Let's assume we have the following field defined as a unique key for our Solr collection. So, in your schema.xml
file, you would have the following:
In your
fields
section you would have the following:<field name="id" type="string" indexed="true" stored="true" required="true" />
After your fields section the following entry could be found:
<uniqueKey>id</uniqueKey>
The following steps will help...