Created
October 10, 2019 18:45
-
-
Save prestonmcgowan/2d34ec381bdc9654aa79bbad7712a289 to your computer and use it in GitHub Desktop.
Report on MarkLogic Element Range Indexes
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
xquery version "1.0-ml"; | |
import module namespace admin = "http://marklogic.com/xdmp/admin" at "/MarkLogic/admin.xqy"; | |
declare namespace db ="http://marklogic.com/xdmp/database"; | |
let $constraint := cts:collection-query("content") | |
let $config := admin:get-configuration() | |
let $indexes := admin:database-get-range-element-indexes($config, xdmp:database())[./db:scalar-type/text() eq "string"] | |
let $last-time := xs:dayTimeDuration("PT0S") | |
return | |
element index-report { | |
attribute type { "string element-range-indexes" }, | |
attribute total-documents { fn:count( cts:uris("", (), $constraint) ) }, | |
attribute total-indexes { fn:count($indexes) }, | |
for $i in $indexes | |
let $ns := $i//db:namespace-uri/text() | |
let $localname := $i//db:localname/text() | |
let $count := fn:count( cts:element-values(fn:QName($ns, $localname), (), (), $constraint) ) | |
let $now := xdmp:elapsed-time() | |
let $duration := $now - $last-time | |
let $_save := xdmp:set($last-time, $now) | |
order by $count descending | |
return element index { | |
attribute ns { $ns }, | |
attribute localname { $localname }, | |
attribute total-values { $count }, | |
attribute sample-time { $duration } | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment