Skip to content

Instantly share code, notes, and snippets.

@dmcassel
Created September 15, 2015 18:21
Show Gist options
  • Save dmcassel/511d0c6a869666b99b4f to your computer and use it in GitHub Desktop.
Save dmcassel/511d0c6a869666b99b4f to your computer and use it in GitHub Desktop.
var admin = require("/MarkLogic/admin");
// Use the (XQuery) Admin APIs to create some indexes.
var config = admin.getConfiguration();
try {
// Create a dateTime index on the registered property. For the purposes of
// creating range indexes a JSON property is the same as an XML element (i.e.
// this will also add XML elements named "registered" in no namespace to this
// index.) Since JSON lacks a native Date type (though JavaScript has one),
// the indexer automatically parses strings that are formatted as ISO8601
// dates, e.g. {"registered": "2014-01-31T19:57:33+08:00"}
config = admin.databaseAddRangeElementIndex(config, xdmp.database(),
admin.databaseRangeElementIndex("dateTime", null, "registered", null, true, "ignore")
);
} catch(err) {
if(err.name != "ADMIN-DUPLICATECONFIGITEM") { throw err; } // Ignore the error if we've already got this index
}
try {
// JSON nodes support full XPath evaluation. Similarly, you can use XPath to specify path indexes on JSON documents.
config = admin.databaseAddRangePathIndex(config, xdmp.database(),
admin.databaseRangePathIndex(xdmp.database(), "double", "balance/value", null, false, "ignore")
);
} catch(err) {
if(err.name != "ADMIN-DUPLICATECONFIGITEM") { throw err; }
}
admin.saveConfiguration(config);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment