The database I am working on has a multi-tenant design. I want to implement hibernate search on my application however I want hibernate search to index a certain tenant only. How do I achieve that?
Asked
Active
Viewed 379 times
1 Answers
3
You should be able to use dynamic sharding - http://docs.jboss.org/hibernate/stable/search/reference/en-US/html_single/#advanced-features-dynamic-sharding
This allows you to split (shard) the data into several Lucene indexes. Using dynamic sharding you can route the data at index and query time using a custom ShardIdentifierProvider
. This requires of course that in the implementation you have access to the tenant id, for example via a ThreadLocal
.

Hardy
- 18,659
- 3
- 49
- 65
-
But how do I index an existing tenant? the mass indexer is not working. the code runs but nothing is happening. btw can you give an example? how do I configure SHardIdentiferProvider using Spring? Spring is the one responsible for identifying which tenant is currently active – KyelJmD Jun 20 '14 at 09:30
-
If you really just want to re-index for a single tenant, you can also use the indexing api - http://docs.jboss.org/hibernate/stable/search/reference/en-US/html_single/#search-batchindex-flushtoindexes. In this case you can write a (Critera) query which only loads the data for a single tenant. Mass indexer should also work, but you basically would re-index for all tenants. No idea why it is not working. You need to provide more context/code in this case. – Hardy Jun 20 '14 at 11:04
-
A ShardIdentiferProvider is configured via a property hibernate.search.[default|
].sharding_strategy. Just set the property the same way you are specifying other Hibernate Search properties. Either via the config file or via the Spring XML config. – Hardy Jun 20 '14 at 11:04 -
Will I replace the [default|
] with something? or that's it? – KyelJmD Jun 20 '14 at 11:56 -
can't I use Spring Data jpa QUery to load data for a single tenant? – KyelJmD Jun 20 '14 at 12:05