Posts Photos Archives About

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


# / / notes / #marklogic #questions #stackoverflow #software-development / Syndicated: stackexchange / 💬 2

Last modified at: Jan. 17, 2021, 5:09 a.m. Source file


Tamas said...

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);

'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.

kcoleman said...

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:[id-or-name]/properties

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

<database-properties xmlns="">

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.