3.3. Sharing indexes (two entities into the same directory)
Note
This is only presented here so that you know the option is available. There is really not much benefit in sharing indexes.
It is technically possible to store the information of more than one entity into a single Lucene index. There are two ways to accomplish this:
- Configuring the underlying directory providers to point to the same physical index directory. In practice, you set the property
hibernate.search.[fully qualified entity name].indexName
to the same value. As an example let’s use the same index (directory) for theFurniture
andAnimal
entity. We just setindexName
for both entities to for example “Animal”. Both entities will then be stored in the Animal directoryhibernate.search.org.hibernate.search.test.shards.Furniture.indexName = Aninal hibernate.search.org.hibernate.search.test.shards.Animal.indexName = Aninal
- Setting the
@Indexed
annotation’sindex
attribute of the entities you want to merge to the same value. If we again wanted allFurniture
instances to be indexed in theAnimal
index along with all instances ofAnimal
we would specify@Indexed(index=”Animal”)
on bothAnimal
andFurniture
classes.