see on GitHub

Operations: Server: How to Compact a Database

To compact database, please use CompactDatabaseOperation. You can choose what should be compacted: documents and/or listed indexes.

Syntax

public CompactDatabaseOperation(CompactSettings compactSettings)

public class CompactSettings {
    private String databaseName;
    private boolean documents;
    private String[] indexes;

    // getters and setters
}

Parameters
DatabaseName String Name of a database to compact
Documents boolean Indicates if documents should be compacted
Indexes String[] List of index names to compact

Example I

CompactSettings settings = new CompactSettings();
settings.setDatabaseName("Northwind");
settings.setDocuments(true);
settings.setIndexes(new String[] { "Orders/Totals", "Orders/ByCompany" });

Operation operation = store.maintenance().server().sendAsync(new CompactDatabaseOperation(settings));
operation.waitForCompletion();

Example II

// get all index names
String[] indexNames = store.maintenance().send(new GetIndexNamesOperation(0, Integer.MAX_VALUE));

CompactSettings settings = new CompactSettings();
settings.setDatabaseName("Northwind");
settings.setDocuments(true);
settings.setIndexes(indexNames);

// compact entire database: documents + all indexes
Operation operation = store.maintenance().server().sendAsync(new CompactDatabaseOperation(settings));
operation.waitForCompletion();

Remarks

The compacting operation is executed asynchronously and during this operation the database will be offline.