Roy Tang

Programmer, engineer, scientist, critic, gamer, dreamer, and kid-at-heart.

Blog Notes Photos Links Archives About

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

Thanks

Comments

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.

I believe you can do this using the REST Management API method PUT /manage/v2/databases/{dbid}/properties. If you pass a payload in which the range-element-indexes property is empty, I think it removes any existing ones.

Take a look at the following:

http://docs.marklogic.com/REST/PUT/manage/v2/databases/[id-or-name]/properties

You’d want to use a payload similar to the following for XML:

<database-properties xmlns="http://marklogic.com/manage">
<range-element-indexes/>
</database-properties>

Or like this for JSON:

{ "range-element-index": [] }

Be careful, though: It’s a sharp tool. You’ll also delete pre-defined indexes like the ones for DLS. I think that’s also true of Tamas’ solution, but did not confirm.