// Proceed only if searchable
if (!MappingUtil.isSearchable(modelClass)) {
continue;
}
final Factory factory = Model.Manager.factoryFor(modelClass);
final long count = factory.count(null, null, null);
// Defensively avoid overflow leading to infinite loop below
if (count > Integer.MAX_VALUE) {
throw new RuntimeException(String.format("Number of entities %s to index is too large (%d)", modelClass, count));
}
Logger.info("Reindexing %s entities of type %s", count, modelClass);
long offset = 0;
// loop over pages
while (offset < count) {
final List results = factory.fetch((int) offset, PAGE_SIZE, null, null, null, null, null);
// loop over individual entities within one page
for (final Object o : results) {
ElasticSearch.index((Model) o, deliveryMode);
}
offset += PAGE_SIZE;