Skip to main content

Administrating MarkLogic Server

Defining Path Range Indexes

To define a range index expressed by an XPath expression, follow these steps:

  1. If you are creating a path range index over XML data, create bindings for any namespaces prefixes used in your index XPath expression. For details, see Defining Namespace Prefixes Used in Path Range Indexes and Fields.

  2. Click Databases in the left tree menu. A list of databases appears.

  3. Click your target database.

  4. In the tree menu, under the selected database, click Path Range Indexes.

  5. Click the Add tab.

  6. From the Scalar Type list, select the type of the XML element, XML attribute, or JSON property for which you want to build a range index.

  7. Enter the XPath expression in the Path Expression field. For XML, you can use any namespace prefix you created in Step 1. XPath expressions are summarized in XPath Quick Reference in the XQuery and XSLT Reference Guide. Not all XPath features are supported by path range indexes. For details, see Understanding Path Range Indexes.

    Note

    You can use the cts:valid-index-path function to test whether the path is syntactically correct for use in a path range index.

    You cannot have a path span across a fragment root. Paths should be scoped within fragment roots.

  8. If you selected a scalar type of string in Step 6, the Collation field contains a default collation. You can enter a different collation URI or click the Collation Builder button for a wizard that constructs the collation URI for you based on the language and other parameters you enter. For details about collations, see Language Support in MarkLogic Server in the Search Developer’s Guide.

  9. Set the Range Value Positions field to true to increase the speed of searches that use cts:near-query and cts:element-query with this index. However, this setting uses more disk space than the default setting of false.

  10. In the invalid values field, choose whether to allow insertion of documents that contain XML elements, XML attributes, or JSON properties on which range index is configured, but the value of those elements, attributes, or properties cannot be coerced to the index data type. You can choose either ignore or reject. By default, the server rejects insertion of such documents. However, if you choose ignore, these documents can be inserted. This setting does not change the behavior of queries on invalid values after documents are inserted into the database. Performing an operation on an invalid value at query time can still result in an error.

  11. To add more indexes, click More Items and repeat Step 6 - Step 10 for each index as needed.

  12. Scroll to the top or bottom and click OK.

The new path range index is added to the database. These rules are applied to XML or JSON documents loaded into the specified database from this point on.

Note

If you have reindexing enabled for the database and you specify an XML element, XML attribute, or JSON property that exists in a document, reindexing will run in the background. When the reindexing is complete, the new index will become available to queries.

Once you have created a path range index, you cannot change the path expression. Instead, you must remove the existing path range index and create a new one with the updated path expression.