Created
October 10, 2019 18:44
-
-
Save prestonmcgowan/12e38c4dd56ed0dad18dff8db05e55b6 to your computer and use it in GitHub Desktop.
Report of MarkLogic Element Attribute Range Indexes
This file contains 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-attribute-indexes($config, xdmp:database())[./db:scalar-type/text() eq "string"] | |
let $last-time := xs:dayTimeDuration("PT0S") | |
return | |
element index-report { | |
attribute type { "string element-attribute-range-indexes" }, | |
attribute total-documents { fn:count( cts:uris("", (), $constraint) ) }, | |
attribute total-indexes { fn:count($indexes) }, | |
for $i in $indexes | |
let $parent-ns := $i//db:parent-namespace-uri/text() | |
let $parent-localname := $i//db:parent-localname/text() | |
let $ns := $i//db:namespace-uri/text() | |
let $localname := $i//db:localname/text() | |
let $count := fn:count( cts:element-attribute-values(fn:QName($parent-ns, $parent-localname), 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 parent-ns { $parent-ns }, | |
attribute parent-localname { $parent-localname }, | |
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