Loading TOC...


   $element-name as xs.QName[],
   $query as cts.query
) as cts.elementQuery


Returns a cts:query matching elements by name with the content constrained by the given cts:query in the second parameter. Searches for matches in the specified element and all of its descendants. If the specified query in the second parameter has any cts:element-attribute-*-query constructors, it will search attributes directly on the specified element and attributes on any descendant elements (see the second example below).

$element-name One or more element QNames to match. When multiple QNames are specified, the query matches if any QName matches.
$query A query for the element to match. If a string is entered, the string is treated as a cts:word-query of the specified string.

Usage Notes

Enabling both the word position and element position indexes ("word position" and "element word position" in the database configuration screen of the Admin Interface) will speed up query performance for many queries that use cts:element-query. The position indexes enable MarkLogic Server to eliminate many false-positive results, which can reduce disk I/O and processing, thereby speeding the performance of many queries. The amount of benefit will vary depending on your data.

You can query for the existence of an element by specifying an empty cts.andQuery as the second parameter. For example, the following will match any instance of the specified element:

    cts.andQuery( [] ))


      "MarkLogic Corporation"))

  => .. relevance-ordered sequence of 'module' elements
  ancestors (or self) of elements with QName 'function'
  and text content containing the phrase 'MarkLogic


const x = xdmp.unquote('<a attr="something">hello</a>');
cts.contains(x, cts.elementQuery(xs.QName("a"),
         xs.QName("attr"), "something"),
// returns true

Stack Overflow iconStack Overflow: Get the most useful answers to questions from the MarkLogic community, or ask your own question.


The commenting feature on this page is enabled by a third party. Comments posted to this page are publicly visible.