Search code examples
marklogic

Marklogic: Delete all element range indexes on a database?


Is there an easy way to delete all the element range indexes on a given database?

Thanks


Solution

  • You could write some script to do this, for example in JavaScript which you need to execute from your Query Console:

    'use strict';
    
    const admin = require('/MarkLogic/admin');
    const config = admin.getConfiguration();
    const db = xdmp.database('Documents');
    
    const indexes = admin.databaseGetRangeElementIndexes(config, db);
    const newConfig = admin.databaseDeleteRangeElementIndex(config, db, indexes);
    admin.saveConfiguration(newConfig);
    
    'All Range Indexes have been removed.'
    

    The above goes through all the Element Range Indexes for the 'Documents' database and removes them - including any pre-defined Range Indexes for DLS.