<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://tech.churchofjesuschrist.org/wiki/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=Bowersmt</id>
	<title>TechWiki - User contributions [en]</title>
	<link rel="self" type="application/atom+xml" href="https://tech.churchofjesuschrist.org/wiki/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=Bowersmt"/>
	<link rel="alternate" type="text/html" href="https://tech.churchofjesuschrist.org/wiki/Special:Contributions/Bowersmt"/>
	<updated>2026-04-14T21:47:08Z</updated>
	<subtitle>User contributions</subtitle>
	<generator>MediaWiki 1.43.3</generator>
	<entry>
		<id>https://tech.churchofjesuschrist.org/wiki/index.php?title=What_is_MarkLogic%3F&amp;diff=70600</id>
		<title>What is MarkLogic?</title>
		<link rel="alternate" type="text/html" href="https://tech.churchofjesuschrist.org/wiki/index.php?title=What_is_MarkLogic%3F&amp;diff=70600"/>
		<updated>2014-11-24T16:15:06Z</updated>

		<summary type="html">&lt;p&gt;Bowersmt: Updated text&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;br /&gt;
[[MarkLogic|« Back to MarkLogic]]&lt;br /&gt;
&lt;br /&gt;
== Describing MarkLogic ==&lt;br /&gt;
[http://www.marklogic.com/what-is-marklogic/ MarkLogic] is a [http://www.marklogic.com/what-is-marklogic/inside-marklogic/ &#039;&#039;&#039;REST application server&#039;&#039;&#039;, &#039;&#039;&#039;document database&#039;&#039;&#039;, and &#039;&#039;&#039;search engine&#039;&#039;&#039;]. It is REST through and through. It is built specifically for hypertext documents, links, metadata, URIs, MIME types, and HTTP. It is schema-agnostic because it is automatically aware of the independent structure of each of its JSON and XML documents. It is search-centric because it can search for &#039;&#039;any combination&#039;&#039; of words, values, structures, and links within and across documents. It scales horizontally to hundreds of servers within and between data centers while maintaining ACID-compliant transactions. &lt;br /&gt;
&lt;br /&gt;
MarkLogic has the following [http://www.marklogic.com/what-is-marklogic/enterprise-nosql/ enterprise features]:&lt;br /&gt;
* [http://www.marklogic.com/resources/java-developers-guide/ Java APIs]&lt;br /&gt;
* [http://en.wikipedia.org/wiki/Node.js Node.js APIs]&lt;br /&gt;
* [http://developer.marklogic.com/learn/2009-07-search-api-walkthrough Search] and [http://developer.marklogic.com/learn/arch/search-and-indexing Query]&lt;br /&gt;
* [http://www.marklogic.com/blog/can-you-pass-the-acid-test/ ACID Transactions]&lt;br /&gt;
* [http://www.marklogic.com/resources/marklogic-high-availability-and-disaster-recovery/resource_download/datasheets/ High Availability] and [http://docs.marklogic.com/guide/database-replication/dbrep_intro#chapter Disaster Recovery]&lt;br /&gt;
* [http://www.marklogic.com/resources/marklogic-flexible-replication/resource_download/datasheets/ Replication within and across data centers]&lt;br /&gt;
* [http://docs.marklogic.com/guide/admin/security#chapter Government-grade Security]&lt;br /&gt;
* [https://docs.marklogic.com/guide/cluster.pdf Scalability] and [https://docs.marklogic.com/guide/admin/database-rebalancing#chapter Elasticity]&lt;br /&gt;
* [https://docs.marklogic.com/guide/ec2/managing#chapter On-premise or Cloud Deployment (especially AWS)]&lt;br /&gt;
* [http://www.marklogic.com/resources/marklogic-and-hadoop/resource_download/datasheets/ Hadoop for Storage and Compute]&lt;br /&gt;
* [http://www.marklogic.com/resources/marklogic-semantics-mlw14/ Semantics]&lt;br /&gt;
&lt;br /&gt;
== What is REST? ==&lt;br /&gt;
REST is an architectural style that uses a uniform resource identifier (&#039;&#039;&#039;URI&#039;&#039;&#039;) and a web protocol (&#039;&#039;&#039;HTTP/HTTPS&#039;&#039;&#039;) to request and transfer a representation (&#039;&#039;&#039;MIME media type&#039;&#039;&#039;) of the state of a resource (&#039;&#039;&#039;document&#039;&#039;&#039;) at a point in time from a server to a client. &lt;br /&gt;
&lt;br /&gt;
REST was coined and defined by Roy Fielding in his &lt;br /&gt;
[http://www.ics.uci.edu/~fielding/pubs/dissertation/top.htm dissertation, &#039;&#039;Architectural Styles and the Design of Network-based Software Architectures&#039;&#039;].  REST standardizes and documents the patterns used in the world wide web: self-documenting hypertext with data and metadata (HTML), stateless request/response communication protocol (HTTP/HTTPS), resource locators (URL), multiple representations per URL (MIME types), and downloading code on demand to process resources (JavaScript, CSS, etc.).&lt;br /&gt;
&lt;br /&gt;
REST consists of three main concepts: &lt;br /&gt;
* (RE) Representation&lt;br /&gt;
* (S)  State &lt;br /&gt;
* (T)  Transfer &lt;br /&gt;
&lt;br /&gt;
== Why is MarkLogic RESTful? ==&lt;br /&gt;
&lt;br /&gt;
=== &#039;&#039;&#039;Representation and MarkLogic&#039;&#039;&#039; === &lt;br /&gt;
* A representation is a document that represents a resource. It has three requirements: MIME media type, URI, and hypertext.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;MIME type:&#039;&#039;&#039; Each resource can be represented by one or more types of documents. The MIME media type defines the representation a client requests. A client may request the resource to be represented as JSON, XML, HTML, PNG, PDF, etc. &lt;br /&gt;
**&#039;&#039;&#039;MarkLogic&#039;&#039;&#039; stores any type of document and assigns the appropriate [http://developer.marklogic.com/blog/document-formats-part2 MIME type] to it. It can fully index, query, search, and process JSON, XML, and RDF documents. It meets the REST requirement of being able to transform JSON, XML, and RDF documents into any other MIME type. It knows how to execute JavaScript, XQuery, XSLT, and SPARQL documents. It knows how [http://docs.marklogic.com/guide/cpf/default#chapter to transform into XHTML] the content, formatting, and structure of Microsoft Word, PowerPoint, Excel, textual PDF, DocBook, and CSS  documents. (It can also use Microsoft Office to create, edit, and manage content in MarkLogic.) It knows how to [https://docs.marklogic.com/guide/search-dev/binary-document-metadata extract metadata and text from over 138 types of binary documents], such as raster images, vector images, videos, archive files, database files, encoded emails, presentations, spreadsheets, word-processing documents, text formats. &lt;br /&gt;
**Few NoSQL databases use MIME types to identify the media type of each document.  Most NoSQL databases support only one type of data and it is usually proprietary: columnar, BSON, binary, etc. Most cannot transform from one MIME type to another.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;URI:&#039;&#039;&#039; A resource is identified by a globally unique identifier (URI). &#039;&#039;&#039;MarkLogic&#039;&#039;&#039; identifies each document with a [http://developer.marklogic.com/try/rest/page2 unique URI]. A document in MarkLogic is like a row in a table in a schema in a relational database. A URI is liberating. It provides random access to any resource anywhere. It is like being able to retrieve any row in any table in any schema of a relational database without having to know what table and schema the row is stored in.  &lt;br /&gt;
**Navigating URL hierarchy is fundamental to REST. MarkLogic understands the hierarchy within a URI, which is represented by slashes &amp;quot;/&amp;quot;, such as https://www.lds.org/scriptures/ot/gen/1  MarkLogic treats the items between the slashes as folders. The URI of each document automatically places it in a folder in a folder hierarchy. A URI automatically defines the folder hierarchy.  In the example URI above, the document for Genesis chapter 1, is located in the Genesis folder, which is located in the Old Testament folder, which is located in the Scriptures folder on lds.org.  &#039;&#039;&#039;MarkLogic&#039;&#039;&#039; indexes the documents in each folder and its subfolders. This makes it fast and easy to retrieve any or all documents in any folder and/or its subfolders.&lt;br /&gt;
**Few NoSQL databases use the URI as the primary key for their documents or data. They also don&#039;t index the URI hierarchically to filter documents by folder and subfolder.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Hypertext:&#039;&#039;&#039; A document should contain data that represents the resource. The data should be &#039;&#039;&#039;human readable and self-documenting&#039;&#039;&#039;, like JSON, XML, RDF, and HTML. It should be &#039;&#039;&#039;linked data&#039;&#039;&#039; (i.e. the &amp;quot;hyper&amp;quot; in &amp;quot;hypertext&amp;quot;). A document should contain &#039;&#039;&#039; metadata links&#039;&#039;&#039; about the resource, such as RDF. It should contain &#039;&#039;&#039;action links&#039;&#039;&#039; to define what further actions can be done with the resource. It should contain &#039;&#039;&#039;related links&#039;&#039;&#039; to related resources, such as images, audio, video, related documents, etc. Each related link should define what actions can be done with the referenced resource, such as download it, display a link to it, execute a command against it, etc.)&lt;br /&gt;
**&#039;&#039;&#039;Hypertext&#039;&#039;&#039; or &#039;&#039;&#039;hypermedia&#039;&#039;&#039; documents must have all these features. Hyperlinks are what the &amp;quot;hyper&amp;quot; in hypertext and hypermedia refers to.  You can&#039;t have REST without &#039;&#039;metadata links&#039;&#039; to define what the data means, &#039;&#039;action links&#039;&#039; to know how to work with the resource, and &#039;&#039;related links&#039;&#039; to connect resources. It should all be human readable and self-documenting so a developer does not have to read documentation to know how to interact with a REST web service and its documents. &lt;br /&gt;
** &#039;&#039;&#039;MarkLogic&#039;&#039;&#039; meets all the requirements for hypertext representation. It is designed around MIME types, URIs, and Linked data.  It stores documents with their MIME types as [http://www.w3schools.com/json/ JSON], [http://www.w3schools.com/xml/ XML], [http://www.w3schools.com/webservices/ws_rdf_intro.asp RDF], [http://www.w3schools.com/html/ HTML], etc.  These documents are human-readable and self-documenting, which MarkLogic leverages to recognize and index each document&#039;s data, data structure, metadata links, action links, and related links. This makes it easy to &#039;&#039;&#039;search&#039;&#039;&#039;, &#039;&#039;&#039;query&#039;&#039;&#039;, &#039;&#039;&#039;transform&#039;&#039;&#039;, and &#039;&#039;&#039;deliver&#039;&#039;&#039; hypertext documents.  MarkLogic can also store any type of binary document and deliver it as a related resource, such as an image, video, or audio. MarkLogic is designed to process simple links and RDF links using [http://en.wikipedia.org/wiki/SPARQL SPARQL] and [https://docs.marklogic.com/xinc XInclude]. MarkLogic can represent links in many formats:  [https://docs.marklogic.com/xp XPointer], [https://docs.marklogic.com/guide/semantics/loading#id_97709 RDF/XML], [https://docs.marklogic.com/guide/semantics/loading#id_79194 RDF/JSON], [https://docs.marklogic.com/guide/semantics/loading#id_73211 Turtle], [https://docs.marklogic.com/guide/semantics/loading#id_70596 N-Triples], [https://docs.marklogic.com/guide/semantics/loading#id_61596 N-Quads], and [https://docs.marklogic.com/guide/semantics/loading#id_74485 TriG].&lt;br /&gt;
**No other NoSQL database natively indexes and fully processes all the document types required for REST hypertext: JSON, XML, RDF, HTML, CSS, and JavaScript.&lt;br /&gt;
&lt;br /&gt;
=== &#039;&#039;&#039;State and MarkLogic&#039;&#039;&#039; === &lt;br /&gt;
* State in REST exists on clients and in documents, data, and state machine data stored in servers. It does not exist in the communications protocol or in session data. It often exists in caches.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Server:&#039;&#039;&#039; All information needed to process a request must be presented in the request and processed against documents in the database. State must only be in the request and in database documents: state cannot be anywhere else, such as in a session cache. The documents in the server define the state of the server. A REST server should explicitly create a state machine that defines the acceptable actions that can transacted against documents in specific contexts.&lt;br /&gt;
**A REST transaction occurs at a &#039;&#039;&#039;point in time&#039;&#039;&#039;. The state of the data in the request is unchanging, but the state of the documents and state machines in the database are often changing. Since request state and database state are both required to process the request and since shifting state creates unpredictable results, a REST transaction should run at a point in time with unchanging state. Only an ACID-compliant database can ensure consistent state because it isolates each transaction from every other transaction. The only time REST does not need an ACID-compliant database is when database documents do not change, database state machines do not change, or when clients can live with the resultant level of unreliable and unpredictable results.&lt;br /&gt;
**&#039;&#039;&#039;MarkLogic&#039;&#039;&#039; meets all the requirements for REST state.  Its web services are stateless: there is no session cache. It is ACID compliant. It ensures each transaction occurs at a point in time and is isolated from all other transactions. This ensures consistent processing during a transaction -- even across billions of documents. MarkLogic is an [http://en.wikipedia.org/wiki/Multiversion_concurrency_control MVCC] database which provides transaction isolation without slowing the performance of reads -- even when documents being read are being modified simultaneously by other transactions. (Also, like any other ACID database, when multiple updates and deletes compete for the same documents, they will impact each other&#039;s performance because change has to be serialized.)  &lt;br /&gt;
** Most other NoSQL databases are not ACID compliant. They are only suitable for REST services when their documents or data do not change or when the rate of change is slow enough or dispersed enough that it creates an acceptable level of unreliability and unpredictability.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Client:&#039;&#039;&#039; A REST client, such as a web browser or spider, locally maintains transactional state, such as what to do in response to documents and result codes that are returned from server transactions. An application exists only in the client -- not in the server (although, a server may deliver application code to a client, such as when a web server downloads HTML, CSS, and JavaScript to a browser). Client application code decides when to execute web service calls and it ties the results together to accomplish its purpose. This allows multiple authorized applications to reuse web services for a variety of purposes.  &lt;br /&gt;
**The server helps the client know what web service calls are available by providing action links with each response.  Action links are contextual and the context is based on the application account, user account, database documents, links within and between documents, the server state machine, etc. Through action links, the server can inform a client application what web service calls are permissible in any given context.&lt;br /&gt;
**&#039;&#039;&#039;MarkLogic&#039;&#039;&#039; meets the needs of client applications through its built-in ability to process and send action links to clients based on context. MarkLogic supports RDF triples and SPARQL, which enables context to be defined across applications, users, document state, links between documents, server state machine, etc. MarkLogic processes triples very quickly, which enables context to scale to billions of documents, millions of users, etc.&lt;br /&gt;
**&#039;&#039;&#039;MarkLogic&#039;&#039;&#039; also uses application and user permissions to filter which documents are returned to clients.  MarkLogic does this automatically and transparently by adding security filtering constraints into every search and query. This ensures no account can access unauthorized documents. This is fast because all security permissions are built-into MarkLogic&#039;s indexes -- which allows document-level security to scale across billions of documents.&lt;br /&gt;
** Most other NoSQL databases do not provide government-grade, document-level security and they also do not support RDF triples and SPARQL.&lt;br /&gt;
&lt;br /&gt;
Because MarkLogic can provide both the web service and database in one server, it is easy to use the state of the documents and the &lt;br /&gt;
&lt;br /&gt;
=== &#039;&#039;&#039;Transfer and MarkLogic&#039;&#039;&#039; === &lt;br /&gt;
* &#039;&#039;&#039;Transfer&#039;&#039;&#039; in REST is a communication protocol that enables a client to send a hypertext request to a server and receive back a hypertext response. The transfer must be stateless and be a request/response protocol. It must have human readable, self-descriptive headers.  The header must contain metadata about the request, such as the requested resource URI, MIME type of the resource, action to perform on the resource (such as get, put, post, patch, and delete). [http://www.w3schools.com/tags/ref_httpmethods.asp &#039;&#039;&#039;HTTP&#039;&#039;&#039;] (Hypertext transfer protocol) and &#039;&#039;&#039;HTTPS&#039;&#039;&#039; (secure HTTP) are designed specifically for REST (that is why they have &amp;quot;hypertext&amp;quot; in their name).&lt;br /&gt;
&lt;br /&gt;
* All &#039;&#039;&#039;MarkLogic&#039;&#039;&#039; communication is through through HTTP and HTTPS REST services (except for its SQL JDBC feature). This includes all internal cluster communication.  MarkLogic provides out-of-the-box REST interfaces for manipulating resources (insert, update, delete, query, search, transform, etc.) and administering MarkLogic (REST app servers, databases, indexes, clusters, etc).  MarkLogic makes it very easy to create custom REST services because everything in MarkLogic is built around REST and because they provide simple and powerful application server APIs.&lt;br /&gt;
&lt;br /&gt;
== MarkLogic Links ==&lt;br /&gt;
*[[MarkLogic]]&lt;br /&gt;
*[[MarkLogic Query and Search]]&lt;br /&gt;
*[[MarkLogic Training Resources]]&lt;br /&gt;
*[[Installing MarkLogic]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[Category: MarkLogic]]&lt;/div&gt;</summary>
		<author><name>Bowersmt</name></author>
	</entry>
	<entry>
		<id>https://tech.churchofjesuschrist.org/wiki/index.php?title=MarkLogic_Query_and_Search&amp;diff=70587</id>
		<title>MarkLogic Query and Search</title>
		<link rel="alternate" type="text/html" href="https://tech.churchofjesuschrist.org/wiki/index.php?title=MarkLogic_Query_and_Search&amp;diff=70587"/>
		<updated>2014-11-20T04:38:17Z</updated>

		<summary type="html">&lt;p&gt;Bowersmt: Fixed category&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Searching and Querying MarkLogic ==&lt;br /&gt;
Indexes are central to everything you do in MarkLogic. They are central to how MarkLogic stores data, scales massively, and processes data quickly. They are central to how you develop because you have to use MarkLogic&#039;s indexes to query and search documents. You have to understand how MarkLogic&#039;s indexes work to be able to create fast queries. And you have to know how to model document structure to work best with indexes.&lt;br /&gt;
&lt;br /&gt;
=== How does MarkLogic compare to a relational database? ===&lt;br /&gt;
A document in MarkLogic is very much like a row in a relational database, and a document type ties documents together like a table ties rows together. MarkLogic collections group documents together in any way you want. Collections are like views in a relational database, which group together a filtered set of rows from one or more tables, but collections do not join and merge document content and views cannot arbitrarily include any row from any table. A document in MarkLogic can have a flat structure like a relational table, or it can contain complex nestings of data. Each nesting of data in a document represents another table in a relational database. For example, a single document in MarkLogic may represent many relational tables, and how they are nested represents their one-to-one, many-to-one, and many-to-many relationships.&lt;br /&gt;
&lt;br /&gt;
Both MarkLogic and relational databases use indexes to resolve queries without having to scan through all documents or rows. MarkLogic indexes are designed to find any word, phrase, value, element, or element structure — no matter where it occurs in document structure, no matter how many times it occurs within a document, and no matter what type of document contains it. For example, you can search for and return a &amp;lt;tt&amp;gt;&amp;lt;title&amp;gt;&amp;lt;/tt&amp;gt; element and MarkLogic will return the contents of all &amp;lt;tt&amp;gt;&amp;lt;title&amp;gt;&amp;lt;/tt&amp;gt; elements it finds — even if &amp;lt;tt&amp;gt;&amp;lt;title&amp;gt;&amp;lt;/tt&amp;gt; elements are in different types of documents. This is similar to doing a union query across multiple tables in relational databases.&lt;br /&gt;
&lt;br /&gt;
MarkLogic indexes also let you search for words, phrases, values, elements, or element structures in very specific locations, such as in only certain types of documents or within certain document structures, or in specific collections or folders. For example, you can search for and return all &amp;lt;tt&amp;gt;&amp;lt;title&amp;gt;&amp;lt;/tt&amp;gt; elements that are found in the header section of poetry documents in the Shakespeare and Tennyson collections.&lt;br /&gt;
&lt;br /&gt;
MarkLogic is not designed for joining documents like a relational database. A relational join searches for matching values across two or more tables and then merges matching rows into a single row. This can be done in MarkLogic, but you have to write advanced code to iterate through query results to match values across different document types, and merge matching documents into a single document. Also since MarkLogic documents are often nested structures, you can&#039;t simply merge them, you have to copy nested content from one document into a specific nested location in another.&lt;br /&gt;
&lt;br /&gt;
Unlike relational databases, MarkLogic can&#039;t do full table scans; queries must use indexes. In contrast, relational databases often use a full table scan to retrieve every row in a table. A rule of thumb in relational databases is that it is faster to directly read in &#039;&#039;all &#039;&#039;the rows when a query accesses more than roughly 25% of the rows. This is because relational databases use variations of the B-Tree index, which requires 3-4 random IOs to find one row and 1 IO to retrieve the row: this is 4-5 total IOs per row. B-Tree indexes work best for single row look ups, but they become increasingly costly the more rows they retrieve. If an index has to look up 25% of its rows with 4 IOs per row, the database will do the same amount of IO if it reads in all of the rows (1 IO per row). Since sequential IO on disks is faster than random IO, relational databases prefer full table scans when accessing more than about 25% of rows in a table. On analytical data warehouses, full table scans are always preferred.&lt;br /&gt;
&lt;br /&gt;
In addition, a relational database [https://docs.oracle.com/database/121/TGSQL/tgsql_optop.htm#TGSQL234 often directly scans through index data] rather than stepping through its B-Tree structure. Databases use a variety of index scans: full scans, range scans, skip scans, join scans, etc. This is index and table records are stored sequentially on disk. This often makes it faster to take advantage of the speed of sequential disk IO and directly load all index or table rows into RAM and process them in RAM; as opposed to walking a b-tree structure and doing multiple slow random IOs to retrieve each record. For the same reason, row and index scans work well in columnar NoSQL databases.&lt;br /&gt;
&lt;br /&gt;
=== Why do MarkLogic queries have to use Indexes? ===&lt;br /&gt;
To maximize parallelism and to spread processing throughout a cluster, MarkLogic spreads documents across the cluster. MarkLogic automatically creates multiple shards per server and spreads them across all the servers in the cluster. Documents are placed in a shard in the order they are created or modified; thus, documents of all types may be randomly intermixed in a shard. Since a shard is not organized by document type, doing a sequential scan to resolve a query would require retrieving and processing all documents in the database. Full scans are not practical in MarkLogic. All queries and searches need to use indexes. For this reason, MarkLogic automatically indexes almost everything. You can also create additional specialized indexes. MarkLogic indexes are not B-Tree indexes; they are designed to be sharded and queried in parallel across stands, forests, and a database cluster that spans many servers.&lt;br /&gt;
&lt;br /&gt;
=== How does MarkLogic scale horizontally? ===&lt;br /&gt;
Documents in MarkLogic belong to a database. Within a database are one or more servers. Each server may contain zero or more &amp;quot;forests&amp;quot;. Within each forest are one or more &amp;quot;stands&amp;quot;. Within each stand are one or more &amp;quot;trees&amp;quot;. A document is hierarchical so it is called a &amp;quot;tree&amp;quot;. (MarkLogic uses the terms &amp;quot;stand&amp;quot; and &amp;quot;forest&amp;quot; instead of &amp;quot;shard&amp;quot;, but they have the same meaning.)&lt;br /&gt;
&lt;br /&gt;
A client contacts one of the servers in a MarkLogic cluster and initiates a query or search. Because MarkLogic communicates through REST web services, a load balancer can spread requests across the servers in a MarkLogic cluster. The initiating server does the following&lt;br /&gt;
&lt;br /&gt;
# It validates the query request from the client&lt;br /&gt;
# It parses and optimizes the query&lt;br /&gt;
# It sends the query to all servers that have forests in the database&lt;br /&gt;
## Each server sends it to its forests&lt;br /&gt;
## Each forest sends it to each stand&lt;br /&gt;
## Each stand uses its indexes to find matching documents&lt;br /&gt;
### All stands and forests query the indexes in parallel&lt;br /&gt;
## Forests combine the matching document IDs from all their stands&lt;br /&gt;
## Forests sort the matching document IDs (in relevance score order or value order)&lt;br /&gt;
## When complete, each forest returns a sorted iterator to the initiating server&lt;br /&gt;
# When each forest has returned an iterator&lt;br /&gt;
# It walks the sorted iterators from all the forests and combines the results in sorted&lt;br /&gt;
# It retrieves matching documents from its &#039;&#039;Expanded Tree Cache &#039;&#039;or from the forests when documents are not cached&lt;br /&gt;
## forests retrieve documents from their &#039;&#039;Compressed Tree Cache&#039;&#039; or from disk when documents are not cached&lt;br /&gt;
# It filters returned documents to remove false positive matches&lt;br /&gt;
# It optionally transforms documents&lt;br /&gt;
## It creates new documents by extracting matching elements, changing structure, changing file format, etc.&lt;br /&gt;
# It returns all matching (optionally transformed) documents to the requester&lt;br /&gt;
# It saves resulting document IDs when paging query results, so it can return subsequent pages of matching documents in subsequent requests&lt;br /&gt;
&lt;br /&gt;
The initiating server&#039;s process is CPU intensive, serialized, and blocks while waiting on forests. To prevent this from being a bottleneck to the cluster, you can dedicate nodes in the cluster to do nothing but evaluate queries. These are called e-nodes (evaluation nodes). These nodes don&#039;t hold data. If they held data, the &#039;&#039;serialized &#039;&#039;evaluation process would compete with the &#039;&#039;parallel &#039;&#039;index matching process. Instead e-nodes are dedicated to validating, parsing, sorting, filtering, transforming, and paginating documents. They cache documents in the &#039;&#039;Expanded Tree Cache&#039;&#039; to minimize the number of documents they have to retrieve from data nodes (d-nodes). D-nodes only do parallel index processing and sorting. They cache documents in their &#039;&#039;Compressed Tree Cache &#039;&#039;to reduce disk IO.&lt;br /&gt;
&lt;br /&gt;
=== How do you optimize a MarkLogic cluster to run queries faster? ===&lt;br /&gt;
* E-nodes and d-nodes can be scaled independently to match the load.&lt;br /&gt;
* You can optimize an e-node by minimizing its &#039;&#039;Compressed Tree Cache &#039;&#039;and maximizing its &#039;&#039;Expanded Tree Cache&#039;&#039;. An e-node needs a big &#039;&#039;Expanded Tree Cache &#039;&#039;so it doesn&#039;t have to retrieve as many documents from d-nodes. An e-node doesn&#039;t need a &#039;&#039;Compressed Tree Cache &#039;&#039;because it doesn&#039;t have any data.&lt;br /&gt;
* You can optimize a d-node by doing the opposite of the e-node: maximize the &#039;&#039;Compressed Tree Cache &#039;&#039;and minimize the &#039;&#039;Expanded Tree Cache&#039;&#039;. You can also optimize d-nodes by making sure each d-node runs on similar hardware and that each forest has a similar number of documents. This is important because all forests process queries in parallel and the slowest forest holds up each query: e-nodes have to wait until the slowest forest finishes.&lt;br /&gt;
* You can optimize a query by making it unfiltered.&lt;br /&gt;
** This means it is completely resolved by the indexes. Because no filtering is required, the initiating server doesn&#039;t have to verify that documents match.&lt;br /&gt;
* You can optimize a query by eliminating false positives.&lt;br /&gt;
** False positives occur when a query identifies a possible match for a document, but it cannot prove it is a match until the filtering process opens the document and verifies it.&lt;br /&gt;
** False positives happen because MarkLogic only partially indexes certain document items. MarkLogic cannot index everything because it would take too much time and space. For example, MarkLogic has a structure index. It indexes relationships between elements in a document. MarkLogic cannot afford to index each element&#039;s path from itself to every other element. MarkLogic compromises on indexing only parent/child relationships. This is effective in eliminating most non-matching documents, but it can produce false positives. The only way to know if a document is an &#039;&#039;exact &#039;&#039;match, MarkLogic must open the document and verify it.&lt;br /&gt;
** For example, suppose a query searches for the following path: &amp;lt;br&amp;gt;&amp;lt;tt&amp;gt;books/poetry/poem&amp;lt;/tt&amp;gt;The structure index will match documents containing books/poetry and poetry/poem. The resulting documents are a probable match, but could contain false positives, such as &amp;lt;br&amp;gt;&amp;lt;tt&amp;gt;books/poetry/fantasy/poetry/poem&amp;lt;/tt&amp;gt;.&lt;br /&gt;
** You can eliminate false positive structures queries by giving elements unique names. They are unique no matter where in they are in the structure and they are more self-descriptive. Instead of naming an element &amp;quot;line&amp;quot; which can mean many things, you can use the precise name &amp;lt;tt&amp;gt;&amp;quot;poemTextLine&amp;quot;&amp;lt;/tt&amp;gt;.&lt;br /&gt;
* You can optimize a query by greatly limiting how many documents it matches. Design each query to return as few documents as possible.&lt;br /&gt;
** It is expensive to transmit documents. Matching documents have to travel from stands to forests to the initiating server, and to the requester.&lt;br /&gt;
** It is expensive to process documents on the initiating server and the requester.&lt;br /&gt;
** It takes processing time on d-nodes to compare lists of document IDs. The fewer the matching document IDs in one part of the query, the faster the entire query runs.&lt;br /&gt;
** The more matching document IDs, the more work MarkLogic has to do in a d-node to compare, union, intersect, and subract them from matching document IDs returned by other parts of the query.&lt;br /&gt;
** The more matching document IDs, the more sorting MarkLogic has to do in the stands, forests, and initiating server.&lt;br /&gt;
&lt;br /&gt;
=== How does a MarkLogic query compare to map/reduce? ===&lt;br /&gt;
A MarkLogic query or search is similar to map/reduce. When you query or search for documents in a database, MarkLogic spreads the work across all the servers to be executed in parallel. This is like a &#039;&#039;map &#039;&#039;process because indexes filter out non-matching documents by combining term, range, and semantic indexes according to the query map. The results are then &#039;&#039;reduced &#039;&#039;at the forest level and again at the database level and again at the initiating server. This parallel division of responsibilities enables MarkLogic to scale.&lt;br /&gt;
&lt;br /&gt;
== Term, Range, and Semantic Indexes ==&lt;br /&gt;
MarkLogic indexes are not B-Tree indexes. MarkLogic uses &#039;&#039;term&#039;&#039;, &#039;&#039;range&#039;&#039;, and &#039;&#039;semantic &#039;&#039;indexes.&lt;br /&gt;
&lt;br /&gt;
* A &#039;&#039;&#039;term index &#039;&#039;&#039;associates a term with every document that contains the term. For example, in a word index, every word in the database is stored in the index. Associated with each word in the index is a list of each document ID that contains the term.&lt;br /&gt;
* A &#039;&#039;&#039;range index &#039;&#039;&#039;is a double term index: it contains each term and all document IDs that contain that term, and it contains each document ID and all the terms that are in the document.&lt;br /&gt;
* A &#039;&#039;&#039;semantic index &#039;&#039;&#039;is similar to a range index but it is optimized to store triples (three pieces of data: subject, object, and predicate).&lt;br /&gt;
&lt;br /&gt;
Term indexes are fast. Give the index a term, and with one look up, it returns &#039;&#039;all &#039;&#039;documents that contain the term. Term indexes are memory mapped files. They run in RAM unless you run out of RAM and then firmware in the CPU efficiently swaps them to and from disk. Thus, it is best to have enough RAM in a MarkLogic server to contain all indexes in memory.&lt;br /&gt;
&lt;br /&gt;
Unlike B-Tree indexes, term indexes are easily sharded within and between servers. MarkLogic takes advantage of this to run queries in parallel within and across servers. This is how MarkLogic can scale to billions of documents and still return queries and searches in milliseconds.&lt;br /&gt;
&lt;br /&gt;
When documents are inserted or updated, MarkLogic indexes them in RAM (as well as appends the changes to a journal on disk). When documents in RAM start to consume too much RAM, MarkLogic writes them to disk as a &amp;quot;stand&amp;quot; in a &amp;quot;forest&amp;quot; and starts creating a new &amp;quot;stand&amp;quot; in RAM.&lt;br /&gt;
&lt;br /&gt;
When you query or search for documents, MarkLogic goes to the indexes in the stands (which are cached in RAM) and evaluates the query in parallel. Each stand index returns a list of document IDs (a list of numbers) that match the query. MarkLogic takes the document IDs returned by each stand and merges them into a final list of document IDs, which it uses to retrieve the documents from cache or disk. This works well because computers are very fast at sort merging lists of numbers.&lt;br /&gt;
&lt;br /&gt;
MarkLogic uses the same indexes for both queries and searches. This allows you to combine search and query expressions. The main difference between search and query is how documents are sorted: searches sort by relevance and queries sort by values. Another difference is that queries tend to use value indexes and searches tend to use word and phrase indexes.&lt;br /&gt;
&lt;br /&gt;
=== What specific indexes does MarkLogic have? ===&lt;br /&gt;
MarkLogic uses indexes to extract words, values, structures, and links out of documents. An index is an altered view of a document. It enables you to search and query for &#039;&#039;documents &#039;&#039;as if they contained only:&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Words&#039;&#039;&#039;: a flat set of words without structure, such as &amp;lt;br&amp;gt;&amp;lt;tt&amp;gt;[&amp;quot;Mary&amp;quot;, &amp;quot;had&amp;quot;, &amp;quot;a&amp;quot;, &amp;quot;little&amp;quot;, &amp;quot;lamb&amp;quot;]&amp;lt;/tt&amp;gt;&lt;br /&gt;
* &#039;&#039;&#039;Phrases&#039;&#039;&#039;: a flat set of phrases without structure, such as &amp;lt;br&amp;gt;&amp;lt;tt&amp;gt;[&amp;quot;Mary had&amp;quot;, &amp;quot;had a&amp;quot;, &amp;quot;a little&amp;quot;, &amp;quot;little lamb&amp;quot;]&amp;lt;/tt&amp;gt;&lt;br /&gt;
* &#039;&#039;&#039;Elements&#039;&#039;&#039;: a flat set of elements without values, such as &amp;lt;br&amp;gt;&amp;lt;tt&amp;gt;[&amp;quot;poem&amp;quot;, &amp;quot;text&amp;quot;, &amp;quot;line&amp;quot;]&amp;lt;/tt&amp;gt;&lt;br /&gt;
* &#039;&#039;&#039;Element-values&#039;&#039;&#039;: a flat set of elements with string values, such as &amp;lt;br&amp;gt;&amp;lt;tt&amp;gt;&amp;quot;line&amp;quot;: &amp;quot;Mary had a little lamb&amp;quot;&amp;lt;/tt&amp;gt;&lt;br /&gt;
* &#039;&#039;&#039;Element-words&#039;&#039;&#039;: a flat set of elements with words, such as &amp;lt;br&amp;gt;&amp;lt;tt&amp;gt;&amp;quot;line&amp;quot;: [&amp;quot;Mary&amp;quot;, &amp;quot;had&amp;quot;, &amp;quot;a&amp;quot;, &amp;quot;little&amp;quot;, &amp;quot;lamb&amp;quot;]&amp;lt;/tt&amp;gt;&lt;br /&gt;
* &#039;&#039;&#039;Element-phrases&#039;&#039;&#039;: a flat set of elements with phrases, such as &amp;lt;br&amp;gt;&amp;lt;tt&amp;gt;&amp;quot;line&amp;quot;: [&amp;quot;Mary had&amp;quot;, &amp;quot;had a&amp;quot;, &amp;quot;a little&amp;quot;, &amp;quot;little lamb&amp;quot;]&amp;lt;/tt&amp;gt;&lt;br /&gt;
* &#039;&#039;&#039;Element-value lexicon&#039;&#039;&#039;: a flat set of elements with typed values, such as &amp;lt;br&amp;gt;&amp;lt;tt&amp;gt;&amp;quot;lineSequence&amp;quot;: 3 &amp;lt;br&amp;gt;&amp;lt;/tt&amp;gt;or a list, count, or co-occurrence of element values scoped to a database, set of documents, or one document.&lt;br /&gt;
* &#039;&#039;&#039;XPath-structure-value lexicon&#039;&#039;&#039;: a flat set of hierarchical elements with typed values, such as &amp;lt;br&amp;gt;&amp;lt;tt&amp;gt;poem.text.line.lineSequence: 3 &amp;lt;br&amp;gt;&amp;lt;/tt&amp;gt;or a list, count, or co-occurrence of hierarchical element values scoped to a database, set of documents, or one document.&lt;br /&gt;
* &#039;&#039;&#039;Xpath-structure&#039;&#039;&#039;: hierarchical structures without values, such as &amp;lt;br&amp;gt;&amp;lt;tt&amp;gt;poem.text.line&amp;lt;/tt&amp;gt;&lt;br /&gt;
* &#039;&#039;&#039;Xpath-structure-words&#039;&#039;&#039;: hierarchical structures with words, such as &amp;lt;br&amp;gt;&amp;lt;tt&amp;gt;poem.text.line: [&amp;quot;Mary&amp;quot;, &amp;quot;had&amp;quot;, &amp;quot;a&amp;quot;, &amp;quot;little&amp;quot;, &amp;quot;lamb&amp;quot;]&amp;lt;/tt&amp;gt;&lt;br /&gt;
* &#039;&#039;&#039;Xpath-structure-phrases&#039;&#039;&#039;: hierarchical structures with phrases, such as &amp;lt;br&amp;gt;&amp;lt;tt&amp;gt;poem.text.line: [&amp;quot;Mary had&amp;quot;, &amp;quot;had a&amp;quot;, &amp;quot;a little&amp;quot;, &amp;quot;little lamb&amp;quot;]&amp;lt;/tt&amp;gt;&lt;br /&gt;
* &#039;&#039;&#039;Xpath-structure-values&#039;&#039;&#039;: hierarchical structures with values, such as &amp;lt;br&amp;gt;&amp;lt;tt&amp;gt;poem.text.line: &amp;quot;Mary had a little lamb&amp;quot;&amp;lt;/tt&amp;gt;&lt;br /&gt;
* &#039;&#039;&#039;RDF document links&#039;&#039;&#039; to other documents, such as &amp;lt;br&amp;gt;&amp;lt;tt&amp;gt;{&amp;quot;subject&amp;quot;: &amp;quot;[http://example.org/documents/thisDoc http://example.org/documents/thisDoc]&amp;quot;, &amp;lt;br&amp;gt;&amp;quot;predicate&amp;quot;: &amp;quot;[http://example.org/predicates/relatesSomehowTo http://example.org/predicates/relatesSomehowTo]&amp;quot;, &amp;lt;br&amp;gt;&amp;quot;object&amp;quot;: &amp;quot;[http://example.org/documents/thatDoc http://example.org/documents/thatDoc]&amp;quot;}&amp;lt;/tt&amp;gt;&lt;br /&gt;
* &#039;&#039;&#039;RDF abstract links to abstract concepts&#039;&#039;&#039;, such as &amp;lt;br&amp;gt;&amp;lt;tt&amp;gt;{&amp;quot;subject&amp;quot;: &amp;quot;[http://example.org/documents/thisDoc http://example.org/documents/thisDoc]&amp;quot;, &amp;lt;br&amp;gt;&amp;quot;predicate&amp;quot;: &amp;quot;[http://example.org/predicates/relatesSomehowTo http://example.org/predicates/relatesSomehowTo]&amp;quot;, &amp;lt;br&amp;gt;&amp;quot;object&amp;quot;: &amp;quot;[http://example.org/documents/someConceptWithNoDocumentAtTheURI http://example.org/documents/someConceptWithNoDocumentAtTheURI]&amp;quot;}&amp;lt;/tt&amp;gt;&lt;br /&gt;
* &#039;&#039;&#039;RDF data links to data&#039;&#039;&#039;, such as &amp;lt;br&amp;gt;&amp;lt;tt&amp;gt;{&amp;quot;subject&amp;quot;: &amp;quot;[http://example.org/documents/thisDoc http://example.org/documents/thisDoc]&amp;quot;, &amp;lt;br&amp;gt;&amp;quot;predicate&amp;quot;: &amp;quot;[http://example.org/predicates/ageInYears http://example.org/predicates/ageInYears]&amp;quot;, &amp;lt;br&amp;gt;&amp;quot;object&amp;quot;: 12}&amp;lt;/tt&amp;gt;&lt;br /&gt;
&lt;br /&gt;
MarkLogic can combine any of these indexes in any way to find matching documents. It can sort the result by relevance or by value.&lt;br /&gt;
&lt;br /&gt;
Search and query expressions are fully composable; i.e. they can be nested inside each other and combined using AND, OR, and NOT expressions.&lt;br /&gt;
&lt;br /&gt;
== Search Functions in MarkLogic ==&lt;br /&gt;
=== Executing a Search ===&lt;br /&gt;
* [http://docs.marklogic.com/cts:search cts:search] is the most important function because it executes a search and returns matching nodes.&lt;br /&gt;
** &#039;&#039;&#039;You must include an XPath expression&#039;&#039;&#039; to define which nodes to search within and to return.&lt;br /&gt;
*** The search returns nodes, which can be documents, elements, attributes, or text. Thus, a search doesn&#039;t have to return entire documents. Depending on the scope of your XPath statement, it may return entire documents, or one matching node from each document, or many matching nodes from each document.&lt;br /&gt;
** Y&#039;&#039;&#039;ou must include a cts query expression&#039;&#039;&#039; to filter the contents of nodes selected by the XPath expression. This allows you to search for specific content within specific nodes and return only those nodes that contain that content.&lt;br /&gt;
*** MarkLogic limits search results to words, phrases, values, and structures in the query that occur within the nodes specified by the XPath expression.&lt;br /&gt;
&lt;br /&gt;
* &lt;br /&gt;
** &lt;br /&gt;
*** If you want to return entire documents and search within specific elements and attributes, then the XPath expression should specify the root element and the query should use the element and element-attribute queries to limit where the search occurs. &lt;br /&gt;
*** If you want to return all the nodes selected by the XPath expression, you can use the empty query expression: &amp;lt;tt&amp;gt;cts:and-query(())&amp;lt;/tt&amp;gt;. &lt;br /&gt;
&lt;br /&gt;
* &lt;br /&gt;
** You may limit the search to specific forests. You may set options like unfiltered, faceted, unchecked, quality weight, relevance scoring method, and relevance trace.&lt;br /&gt;
** Use Cases:&lt;br /&gt;
*** A search can return entire documents whose contents match the XPath and query expressions.&lt;br /&gt;
*** A search can extract and return titles from documents as long as the contents of the titles match the XPath and query expressions.&lt;br /&gt;
*** A search can extract and return all the paragraphs from documents as long as the contents of the paragraphs match the XPath and query expressions.&lt;br /&gt;
** Notes:&lt;br /&gt;
*** There is no functional difference between searching entire documents and elements because an element has the same structure as document. Both may contain complex nested elements or both may simply contain a value. In both cases, MarkLogic retrieves entire documents. In the case of elements, it extracts the requested elements from each retrieved document.&lt;br /&gt;
*** Searching attributes, text nodes, and childless elements is similar to searching documents and elements with children — except the cts query cannot look for nested structures.&lt;br /&gt;
* [http://docs.marklogic.com/cts:contains cts:contains] is the second most important function because it returns true when a cts query finds at least one matching node in the nodes returned by an XPath expression (or a sequence of values). In other words, it returns true when at least one of the specified nodes &#039;&#039;contains&#039;&#039; the precise combination of words, phrases, values, structures, and/or triples in a cts query.&lt;br /&gt;
* NOTE: in the second example for [http://docs.marklogic.com/cts:not-query cts:not-query], it says cts:contains forces the constraint to happen in the filtering stage of the query. Is this always true for cts:contains, or is it only true in the example?&lt;br /&gt;
&lt;br /&gt;
=== Constructing a Query ===&lt;br /&gt;
You compose a query using cts query constructor functions. You then execute the query by passing it into &amp;lt;tt&amp;gt;cts:search, cts:contains, search:search&amp;lt;/tt&amp;gt;, and lexicon functions. MarkLogic has 30+ query constructors. They all end in &amp;quot;-query&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
==== Composite Query Constructors ====&lt;br /&gt;
The composite query constructors build up new queries from other queries, and queries can be nested within queries.&lt;br /&gt;
&lt;br /&gt;
* [http://docs.marklogic.com/cts:and-query cts:and-query] returns a query that intersects two or more sub-queries. &lt;br /&gt;
** You may optionally specify an &amp;quot;ordered&amp;quot; option that requires document contents to match sub-queries in the order they are listed; for example if the sub-queries are &amp;quot;To be&amp;quot; and &amp;quot;or not to be&amp;quot;, then the query will match documents that have the phrase &amp;quot;To be&amp;quot; before &amp;quot;or not to be&amp;quot;. The default is &amp;quot;unordered&amp;quot;, which allows each sub-query to match the content in any order that it occurs in the document.&lt;br /&gt;
** If you pass in the empty sequence, such as &amp;lt;tt&amp;gt;cts:and-query(())&amp;lt;/tt&amp;gt;, then it will match every document in the database.&lt;br /&gt;
* [http://docs.marklogic.com/cts:or-query cts:or-query] returns a query that unions two or more sub-queries.&lt;br /&gt;
* [http://docs.marklogic.com/cts:not-query cts:not-query] returns a query that subtracts one or more sub-queries.&lt;br /&gt;
** It works by taking the list of all documents in the database and subtracting the documents returned from its sub-queries. It returns all remaining documents. It does not filter documents returned from its sub-queries because filtering happens after all index resolution has completed, and &amp;lt;tt&amp;gt;cts:not-query &amp;lt;/tt&amp;gt;executes during index resolution. Thus, only if its sub-queries return accurate results (with no false-positives), then the results of &amp;lt;tt&amp;gt;cts:not-query&amp;lt;/tt&amp;gt; are accurate. Thus, it only produces accurate results when all its sub-queries are resolvable completely from indexes with no filtering required.&lt;br /&gt;
** &#039;&#039;&#039;Warning&#039;&#039;&#039;: &amp;lt;tt&amp;gt;cts:not-query &amp;lt;/tt&amp;gt;can be inaccurate. It can be missing some documents. This happens when one or more of its sub-queries require filtering (i.e. can&#039;t be resolved accurately using only indexes). When sub-queries require filtering, they may return false-positive matches. A false-positive match occurs when the indexes cannot determine for sure if a document matches; so MarkLogic includes the document just in case. As the last step in a query, MarkLogic opens all potentially matching documents and filters out false-positive matches. Thus, false-positives are not a match, they are a failed potential match. False positives can be prevented by writing sub-queries that are resolved completely by the indexes so that there is no need for filtering.&lt;br /&gt;
** Because &amp;lt;tt&amp;gt;cts:not-query &amp;lt;/tt&amp;gt;runs during index resolution (before filtering occurs), it subtracts out any false-positive matches returned by its sub-queries. False-positives should not be subtracted out. But MarkLogic doesn&#039;t know which documents are false-positives until filtering, and it can&#039;t do filtering during &amp;lt;tt&amp;gt;cts:not-query &amp;lt;/tt&amp;gt;because it is in the middle of doing index resolution. Thus, MarkLogic subtracts out false-positives and this causes &amp;lt;tt&amp;gt;cts:not-query &amp;lt;/tt&amp;gt;to return too few documents. If we prevent sub-queries from returning false-positives, &amp;lt;tt&amp;gt;cts:not-query &amp;lt;/tt&amp;gt;returns accurate results.&lt;br /&gt;
* [http://docs.marklogic.com/cts:and-not-query cts:and-not-query]&lt;br /&gt;
* [http://docs.marklogic.com/cts:element-query cts:element-query]&lt;br /&gt;
* [http://docs.marklogic.com/cts:document-fragment-query cts:document-fragment-query]&lt;br /&gt;
* [http://docs.marklogic.com/cts:locks-query cts:locks-query]&lt;br /&gt;
* [http://docs.marklogic.com/cts:properties-query cts:properties-query]&lt;br /&gt;
* [http://docs.marklogic.com/cts:near-query cts:near-query]&lt;br /&gt;
&lt;br /&gt;
== Training Resources for MarkLogic Search ==&lt;br /&gt;
* [http://developer.marklogic.com/blog/grokking-the-cts-api &amp;quot;Grokking the cts API&amp;quot;] is a great overview of MarkLogic&#039;s search and query capabilities.&lt;br /&gt;
&lt;br /&gt;
[[Category: MarkLogic]]&lt;/div&gt;</summary>
		<author><name>Bowersmt</name></author>
	</entry>
	<entry>
		<id>https://tech.churchofjesuschrist.org/wiki/index.php?title=MarkLogic_Query_and_Search&amp;diff=70586</id>
		<title>MarkLogic Query and Search</title>
		<link rel="alternate" type="text/html" href="https://tech.churchofjesuschrist.org/wiki/index.php?title=MarkLogic_Query_and_Search&amp;diff=70586"/>
		<updated>2014-11-20T04:37:15Z</updated>

		<summary type="html">&lt;p&gt;Bowersmt: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Searching and Querying MarkLogic ==&lt;br /&gt;
Indexes are central to everything you do in MarkLogic. They are central to how MarkLogic stores data, scales massively, and processes data quickly. They are central to how you develop because you have to use MarkLogic&#039;s indexes to query and search documents. You have to understand how MarkLogic&#039;s indexes work to be able to create fast queries. And you have to know how to model document structure to work best with indexes.&lt;br /&gt;
&lt;br /&gt;
=== How does MarkLogic compare to a relational database? ===&lt;br /&gt;
A document in MarkLogic is very much like a row in a relational database, and a document type ties documents together like a table ties rows together. MarkLogic collections group documents together in any way you want. Collections are like views in a relational database, which group together a filtered set of rows from one or more tables, but collections do not join and merge document content and views cannot arbitrarily include any row from any table. A document in MarkLogic can have a flat structure like a relational table, or it can contain complex nestings of data. Each nesting of data in a document represents another table in a relational database. For example, a single document in MarkLogic may represent many relational tables, and how they are nested represents their one-to-one, many-to-one, and many-to-many relationships.&lt;br /&gt;
&lt;br /&gt;
Both MarkLogic and relational databases use indexes to resolve queries without having to scan through all documents or rows. MarkLogic indexes are designed to find any word, phrase, value, element, or element structure — no matter where it occurs in document structure, no matter how many times it occurs within a document, and no matter what type of document contains it. For example, you can search for and return a &amp;lt;tt&amp;gt;&amp;lt;title&amp;gt;&amp;lt;/tt&amp;gt; element and MarkLogic will return the contents of all &amp;lt;tt&amp;gt;&amp;lt;title&amp;gt;&amp;lt;/tt&amp;gt; elements it finds — even if &amp;lt;tt&amp;gt;&amp;lt;title&amp;gt;&amp;lt;/tt&amp;gt; elements are in different types of documents. This is similar to doing a union query across multiple tables in relational databases.&lt;br /&gt;
&lt;br /&gt;
MarkLogic indexes also let you search for words, phrases, values, elements, or element structures in very specific locations, such as in only certain types of documents or within certain document structures, or in specific collections or folders. For example, you can search for and return all &amp;lt;tt&amp;gt;&amp;lt;title&amp;gt;&amp;lt;/tt&amp;gt; elements that are found in the header section of poetry documents in the Shakespeare and Tennyson collections.&lt;br /&gt;
&lt;br /&gt;
MarkLogic is not designed for joining documents like a relational database. A relational join searches for matching values across two or more tables and then merges matching rows into a single row. This can be done in MarkLogic, but you have to write advanced code to iterate through query results to match values across different document types, and merge matching documents into a single document. Also since MarkLogic documents are often nested structures, you can&#039;t simply merge them, you have to copy nested content from one document into a specific nested location in another.&lt;br /&gt;
&lt;br /&gt;
Unlike relational databases, MarkLogic can&#039;t do full table scans; queries must use indexes. In contrast, relational databases often use a full table scan to retrieve every row in a table. A rule of thumb in relational databases is that it is faster to directly read in &#039;&#039;all &#039;&#039;the rows when a query accesses more than roughly 25% of the rows. This is because relational databases use variations of the B-Tree index, which requires 3-4 random IOs to find one row and 1 IO to retrieve the row: this is 4-5 total IOs per row. B-Tree indexes work best for single row look ups, but they become increasingly costly the more rows they retrieve. If an index has to look up 25% of its rows with 4 IOs per row, the database will do the same amount of IO if it reads in all of the rows (1 IO per row). Since sequential IO on disks is faster than random IO, relational databases prefer full table scans when accessing more than about 25% of rows in a table. On analytical data warehouses, full table scans are always preferred.&lt;br /&gt;
&lt;br /&gt;
In addition, a relational database [https://docs.oracle.com/database/121/TGSQL/tgsql_optop.htm#TGSQL234 often directly scans through index data] rather than stepping through its B-Tree structure. Databases use a variety of index scans: full scans, range scans, skip scans, join scans, etc. This is index and table records are stored sequentially on disk. This often makes it faster to take advantage of the speed of sequential disk IO and directly load all index or table rows into RAM and process them in RAM; as opposed to walking a b-tree structure and doing multiple slow random IOs to retrieve each record. For the same reason, row and index scans work well in columnar NoSQL databases.&lt;br /&gt;
&lt;br /&gt;
=== Why do MarkLogic queries have to use Indexes? ===&lt;br /&gt;
To maximize parallelism and to spread processing throughout a cluster, MarkLogic spreads documents across the cluster. MarkLogic automatically creates multiple shards per server and spreads them across all the servers in the cluster. Documents are placed in a shard in the order they are created or modified; thus, documents of all types may be randomly intermixed in a shard. Since a shard is not organized by document type, doing a sequential scan to resolve a query would require retrieving and processing all documents in the database. Full scans are not practical in MarkLogic. All queries and searches need to use indexes. For this reason, MarkLogic automatically indexes almost everything. You can also create additional specialized indexes. MarkLogic indexes are not B-Tree indexes; they are designed to be sharded and queried in parallel across stands, forests, and a database cluster that spans many servers.&lt;br /&gt;
&lt;br /&gt;
=== How does MarkLogic scale horizontally? ===&lt;br /&gt;
Documents in MarkLogic belong to a database. Within a database are one or more servers. Each server may contain zero or more &amp;quot;forests&amp;quot;. Within each forest are one or more &amp;quot;stands&amp;quot;. Within each stand are one or more &amp;quot;trees&amp;quot;. A document is hierarchical so it is called a &amp;quot;tree&amp;quot;. (MarkLogic uses the terms &amp;quot;stand&amp;quot; and &amp;quot;forest&amp;quot; instead of &amp;quot;shard&amp;quot;, but they have the same meaning.)&lt;br /&gt;
&lt;br /&gt;
A client contacts one of the servers in a MarkLogic cluster and initiates a query or search. Because MarkLogic communicates through REST web services, a load balancer can spread requests across the servers in a MarkLogic cluster. The initiating server does the following&lt;br /&gt;
&lt;br /&gt;
# It validates the query request from the client&lt;br /&gt;
# It parses and optimizes the query&lt;br /&gt;
# It sends the query to all servers that have forests in the database&lt;br /&gt;
## Each server sends it to its forests&lt;br /&gt;
## Each forest sends it to each stand&lt;br /&gt;
## Each stand uses its indexes to find matching documents&lt;br /&gt;
### All stands and forests query the indexes in parallel&lt;br /&gt;
## Forests combine the matching document IDs from all their stands&lt;br /&gt;
## Forests sort the matching document IDs (in relevance score order or value order)&lt;br /&gt;
## When complete, each forest returns a sorted iterator to the initiating server&lt;br /&gt;
# When each forest has returned an iterator&lt;br /&gt;
# It walks the sorted iterators from all the forests and combines the results in sorted&lt;br /&gt;
# It retrieves matching documents from its &#039;&#039;Expanded Tree Cache &#039;&#039;or from the forests when documents are not cached&lt;br /&gt;
## forests retrieve documents from their &#039;&#039;Compressed Tree Cache&#039;&#039; or from disk when documents are not cached&lt;br /&gt;
# It filters returned documents to remove false positive matches&lt;br /&gt;
# It optionally transforms documents&lt;br /&gt;
## It creates new documents by extracting matching elements, changing structure, changing file format, etc.&lt;br /&gt;
# It returns all matching (optionally transformed) documents to the requester&lt;br /&gt;
# It saves resulting document IDs when paging query results, so it can return subsequent pages of matching documents in subsequent requests&lt;br /&gt;
&lt;br /&gt;
The initiating server&#039;s process is CPU intensive, serialized, and blocks while waiting on forests. To prevent this from being a bottleneck to the cluster, you can dedicate nodes in the cluster to do nothing but evaluate queries. These are called e-nodes (evaluation nodes). These nodes don&#039;t hold data. If they held data, the &#039;&#039;serialized &#039;&#039;evaluation process would compete with the &#039;&#039;parallel &#039;&#039;index matching process. Instead e-nodes are dedicated to validating, parsing, sorting, filtering, transforming, and paginating documents. They cache documents in the &#039;&#039;Expanded Tree Cache&#039;&#039; to minimize the number of documents they have to retrieve from data nodes (d-nodes). D-nodes only do parallel index processing and sorting. They cache documents in their &#039;&#039;Compressed Tree Cache &#039;&#039;to reduce disk IO.&lt;br /&gt;
&lt;br /&gt;
=== How do you optimize a MarkLogic cluster to run queries faster? ===&lt;br /&gt;
* E-nodes and d-nodes can be scaled independently to match the load.&lt;br /&gt;
* You can optimize an e-node by minimizing its &#039;&#039;Compressed Tree Cache &#039;&#039;and maximizing its &#039;&#039;Expanded Tree Cache&#039;&#039;. An e-node needs a big &#039;&#039;Expanded Tree Cache &#039;&#039;so it doesn&#039;t have to retrieve as many documents from d-nodes. An e-node doesn&#039;t need a &#039;&#039;Compressed Tree Cache &#039;&#039;because it doesn&#039;t have any data.&lt;br /&gt;
* You can optimize a d-node by doing the opposite of the e-node: maximize the &#039;&#039;Compressed Tree Cache &#039;&#039;and minimize the &#039;&#039;Expanded Tree Cache&#039;&#039;. You can also optimize d-nodes by making sure each d-node runs on similar hardware and that each forest has a similar number of documents. This is important because all forests process queries in parallel and the slowest forest holds up each query: e-nodes have to wait until the slowest forest finishes.&lt;br /&gt;
* You can optimize a query by making it unfiltered.&lt;br /&gt;
** This means it is completely resolved by the indexes. Because no filtering is required, the initiating server doesn&#039;t have to verify that documents match.&lt;br /&gt;
* You can optimize a query by eliminating false positives.&lt;br /&gt;
** False positives occur when a query identifies a possible match for a document, but it cannot prove it is a match until the filtering process opens the document and verifies it.&lt;br /&gt;
** False positives happen because MarkLogic only partially indexes certain document items. MarkLogic cannot index everything because it would take too much time and space. For example, MarkLogic has a structure index. It indexes relationships between elements in a document. MarkLogic cannot afford to index each element&#039;s path from itself to every other element. MarkLogic compromises on indexing only parent/child relationships. This is effective in eliminating most non-matching documents, but it can produce false positives. The only way to know if a document is an &#039;&#039;exact &#039;&#039;match, MarkLogic must open the document and verify it.&lt;br /&gt;
** For example, suppose a query searches for the following path: &amp;lt;br&amp;gt;&amp;lt;tt&amp;gt;books/poetry/poem&amp;lt;/tt&amp;gt;The structure index will match documents containing books/poetry and poetry/poem. The resulting documents are a probable match, but could contain false positives, such as &amp;lt;br&amp;gt;&amp;lt;tt&amp;gt;books/poetry/fantasy/poetry/poem&amp;lt;/tt&amp;gt;.&lt;br /&gt;
** You can eliminate false positive structures queries by giving elements unique names. They are unique no matter where in they are in the structure and they are more self-descriptive. Instead of naming an element &amp;quot;line&amp;quot; which can mean many things, you can use the precise name &amp;lt;tt&amp;gt;&amp;quot;poemTextLine&amp;quot;&amp;lt;/tt&amp;gt;.&lt;br /&gt;
* You can optimize a query by greatly limiting how many documents it matches. Design each query to return as few documents as possible.&lt;br /&gt;
** It is expensive to transmit documents. Matching documents have to travel from stands to forests to the initiating server, and to the requester.&lt;br /&gt;
** It is expensive to process documents on the initiating server and the requester.&lt;br /&gt;
** It takes processing time on d-nodes to compare lists of document IDs. The fewer the matching document IDs in one part of the query, the faster the entire query runs.&lt;br /&gt;
** The more matching document IDs, the more work MarkLogic has to do in a d-node to compare, union, intersect, and subract them from matching document IDs returned by other parts of the query.&lt;br /&gt;
** The more matching document IDs, the more sorting MarkLogic has to do in the stands, forests, and initiating server.&lt;br /&gt;
&lt;br /&gt;
=== How does a MarkLogic query compare to map/reduce? ===&lt;br /&gt;
A MarkLogic query or search is similar to map/reduce. When you query or search for documents in a database, MarkLogic spreads the work across all the servers to be executed in parallel. This is like a &#039;&#039;map &#039;&#039;process because indexes filter out non-matching documents by combining term, range, and semantic indexes according to the query map. The results are then &#039;&#039;reduced &#039;&#039;at the forest level and again at the database level and again at the initiating server. This parallel division of responsibilities enables MarkLogic to scale.&lt;br /&gt;
&lt;br /&gt;
== Term, Range, and Semantic Indexes ==&lt;br /&gt;
MarkLogic indexes are not B-Tree indexes. MarkLogic uses &#039;&#039;term&#039;&#039;, &#039;&#039;range&#039;&#039;, and &#039;&#039;semantic &#039;&#039;indexes.&lt;br /&gt;
&lt;br /&gt;
* A &#039;&#039;&#039;term index &#039;&#039;&#039;associates a term with every document that contains the term. For example, in a word index, every word in the database is stored in the index. Associated with each word in the index is a list of each document ID that contains the term.&lt;br /&gt;
* A &#039;&#039;&#039;range index &#039;&#039;&#039;is a double term index: it contains each term and all document IDs that contain that term, and it contains each document ID and all the terms that are in the document.&lt;br /&gt;
* A &#039;&#039;&#039;semantic index &#039;&#039;&#039;is similar to a range index but it is optimized to store triples (three pieces of data: subject, object, and predicate).&lt;br /&gt;
&lt;br /&gt;
Term indexes are fast. Give the index a term, and with one look up, it returns &#039;&#039;all &#039;&#039;documents that contain the term. Term indexes are memory mapped files. They run in RAM unless you run out of RAM and then firmware in the CPU efficiently swaps them to and from disk. Thus, it is best to have enough RAM in a MarkLogic server to contain all indexes in memory.&lt;br /&gt;
&lt;br /&gt;
Unlike B-Tree indexes, term indexes are easily sharded within and between servers. MarkLogic takes advantage of this to run queries in parallel within and across servers. This is how MarkLogic can scale to billions of documents and still return queries and searches in milliseconds.&lt;br /&gt;
&lt;br /&gt;
When documents are inserted or updated, MarkLogic indexes them in RAM (as well as appends the changes to a journal on disk). When documents in RAM start to consume too much RAM, MarkLogic writes them to disk as a &amp;quot;stand&amp;quot; in a &amp;quot;forest&amp;quot; and starts creating a new &amp;quot;stand&amp;quot; in RAM.&lt;br /&gt;
&lt;br /&gt;
When you query or search for documents, MarkLogic goes to the indexes in the stands (which are cached in RAM) and evaluates the query in parallel. Each stand index returns a list of document IDs (a list of numbers) that match the query. MarkLogic takes the document IDs returned by each stand and merges them into a final list of document IDs, which it uses to retrieve the documents from cache or disk. This works well because computers are very fast at sort merging lists of numbers.&lt;br /&gt;
&lt;br /&gt;
MarkLogic uses the same indexes for both queries and searches. This allows you to combine search and query expressions. The main difference between search and query is how documents are sorted: searches sort by relevance and queries sort by values. Another difference is that queries tend to use value indexes and searches tend to use word and phrase indexes.&lt;br /&gt;
&lt;br /&gt;
=== What specific indexes does MarkLogic have? ===&lt;br /&gt;
MarkLogic uses indexes to extract words, values, structures, and links out of documents. An index is an altered view of a document. It enables you to search and query for &#039;&#039;documents &#039;&#039;as if they contained only:&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Words&#039;&#039;&#039;: a flat set of words without structure, such as &amp;lt;br&amp;gt;&amp;lt;tt&amp;gt;[&amp;quot;Mary&amp;quot;, &amp;quot;had&amp;quot;, &amp;quot;a&amp;quot;, &amp;quot;little&amp;quot;, &amp;quot;lamb&amp;quot;]&amp;lt;/tt&amp;gt;&lt;br /&gt;
* &#039;&#039;&#039;Phrases&#039;&#039;&#039;: a flat set of phrases without structure, such as &amp;lt;br&amp;gt;&amp;lt;tt&amp;gt;[&amp;quot;Mary had&amp;quot;, &amp;quot;had a&amp;quot;, &amp;quot;a little&amp;quot;, &amp;quot;little lamb&amp;quot;]&amp;lt;/tt&amp;gt;&lt;br /&gt;
* &#039;&#039;&#039;Elements&#039;&#039;&#039;: a flat set of elements without values, such as &amp;lt;br&amp;gt;&amp;lt;tt&amp;gt;[&amp;quot;poem&amp;quot;, &amp;quot;text&amp;quot;, &amp;quot;line&amp;quot;]&amp;lt;/tt&amp;gt;&lt;br /&gt;
* &#039;&#039;&#039;Element-values&#039;&#039;&#039;: a flat set of elements with string values, such as &amp;lt;br&amp;gt;&amp;lt;tt&amp;gt;&amp;quot;line&amp;quot;: &amp;quot;Mary had a little lamb&amp;quot;&amp;lt;/tt&amp;gt;&lt;br /&gt;
* &#039;&#039;&#039;Element-words&#039;&#039;&#039;: a flat set of elements with words, such as &amp;lt;br&amp;gt;&amp;lt;tt&amp;gt;&amp;quot;line&amp;quot;: [&amp;quot;Mary&amp;quot;, &amp;quot;had&amp;quot;, &amp;quot;a&amp;quot;, &amp;quot;little&amp;quot;, &amp;quot;lamb&amp;quot;]&amp;lt;/tt&amp;gt;&lt;br /&gt;
* &#039;&#039;&#039;Element-phrases&#039;&#039;&#039;: a flat set of elements with phrases, such as &amp;lt;br&amp;gt;&amp;lt;tt&amp;gt;&amp;quot;line&amp;quot;: [&amp;quot;Mary had&amp;quot;, &amp;quot;had a&amp;quot;, &amp;quot;a little&amp;quot;, &amp;quot;little lamb&amp;quot;]&amp;lt;/tt&amp;gt;&lt;br /&gt;
* &#039;&#039;&#039;Element-value lexicon&#039;&#039;&#039;: a flat set of elements with typed values, such as &amp;lt;br&amp;gt;&amp;lt;tt&amp;gt;&amp;quot;lineSequence&amp;quot;: 3 &amp;lt;br&amp;gt;&amp;lt;/tt&amp;gt;or a list, count, or co-occurrence of element values scoped to a database, set of documents, or one document.&lt;br /&gt;
* &#039;&#039;&#039;XPath-structure-value lexicon&#039;&#039;&#039;: a flat set of hierarchical elements with typed values, such as &amp;lt;br&amp;gt;&amp;lt;tt&amp;gt;poem.text.line.lineSequence: 3 &amp;lt;br&amp;gt;&amp;lt;/tt&amp;gt;or a list, count, or co-occurrence of hierarchical element values scoped to a database, set of documents, or one document.&lt;br /&gt;
* &#039;&#039;&#039;Xpath-structure&#039;&#039;&#039;: hierarchical structures without values, such as &amp;lt;br&amp;gt;&amp;lt;tt&amp;gt;poem.text.line&amp;lt;/tt&amp;gt;&lt;br /&gt;
* &#039;&#039;&#039;Xpath-structure-words&#039;&#039;&#039;: hierarchical structures with words, such as &amp;lt;br&amp;gt;&amp;lt;tt&amp;gt;poem.text.line: [&amp;quot;Mary&amp;quot;, &amp;quot;had&amp;quot;, &amp;quot;a&amp;quot;, &amp;quot;little&amp;quot;, &amp;quot;lamb&amp;quot;]&amp;lt;/tt&amp;gt;&lt;br /&gt;
* &#039;&#039;&#039;Xpath-structure-phrases&#039;&#039;&#039;: hierarchical structures with phrases, such as &amp;lt;br&amp;gt;&amp;lt;tt&amp;gt;poem.text.line: [&amp;quot;Mary had&amp;quot;, &amp;quot;had a&amp;quot;, &amp;quot;a little&amp;quot;, &amp;quot;little lamb&amp;quot;]&amp;lt;/tt&amp;gt;&lt;br /&gt;
* &#039;&#039;&#039;Xpath-structure-values&#039;&#039;&#039;: hierarchical structures with values, such as &amp;lt;br&amp;gt;&amp;lt;tt&amp;gt;poem.text.line: &amp;quot;Mary had a little lamb&amp;quot;&amp;lt;/tt&amp;gt;&lt;br /&gt;
* &#039;&#039;&#039;RDF document links&#039;&#039;&#039; to other documents, such as &amp;lt;br&amp;gt;&amp;lt;tt&amp;gt;{&amp;quot;subject&amp;quot;: &amp;quot;[http://example.org/documents/thisDoc http://example.org/documents/thisDoc]&amp;quot;, &amp;lt;br&amp;gt;&amp;quot;predicate&amp;quot;: &amp;quot;[http://example.org/predicates/relatesSomehowTo http://example.org/predicates/relatesSomehowTo]&amp;quot;, &amp;lt;br&amp;gt;&amp;quot;object&amp;quot;: &amp;quot;[http://example.org/documents/thatDoc http://example.org/documents/thatDoc]&amp;quot;}&amp;lt;/tt&amp;gt;&lt;br /&gt;
* &#039;&#039;&#039;RDF abstract links to abstract concepts&#039;&#039;&#039;, such as &amp;lt;br&amp;gt;&amp;lt;tt&amp;gt;{&amp;quot;subject&amp;quot;: &amp;quot;[http://example.org/documents/thisDoc http://example.org/documents/thisDoc]&amp;quot;, &amp;lt;br&amp;gt;&amp;quot;predicate&amp;quot;: &amp;quot;[http://example.org/predicates/relatesSomehowTo http://example.org/predicates/relatesSomehowTo]&amp;quot;, &amp;lt;br&amp;gt;&amp;quot;object&amp;quot;: &amp;quot;[http://example.org/documents/someConceptWithNoDocumentAtTheURI http://example.org/documents/someConceptWithNoDocumentAtTheURI]&amp;quot;}&amp;lt;/tt&amp;gt;&lt;br /&gt;
* &#039;&#039;&#039;RDF data links to data&#039;&#039;&#039;, such as &amp;lt;br&amp;gt;&amp;lt;tt&amp;gt;{&amp;quot;subject&amp;quot;: &amp;quot;[http://example.org/documents/thisDoc http://example.org/documents/thisDoc]&amp;quot;, &amp;lt;br&amp;gt;&amp;quot;predicate&amp;quot;: &amp;quot;[http://example.org/predicates/ageInYears http://example.org/predicates/ageInYears]&amp;quot;, &amp;lt;br&amp;gt;&amp;quot;object&amp;quot;: 12}&amp;lt;/tt&amp;gt;&lt;br /&gt;
&lt;br /&gt;
MarkLogic can combine any of these indexes in any way to find matching documents. It can sort the result by relevance or by value.&lt;br /&gt;
&lt;br /&gt;
Search and query expressions are fully composable; i.e. they can be nested inside each other and combined using AND, OR, and NOT expressions.&lt;br /&gt;
&lt;br /&gt;
== Search Functions in MarkLogic ==&lt;br /&gt;
=== Executing a Search ===&lt;br /&gt;
* [http://docs.marklogic.com/cts:search cts:search] is the most important function because it executes a search and returns matching nodes.&lt;br /&gt;
** &#039;&#039;&#039;You must include an XPath expression&#039;&#039;&#039; to define which nodes to search within and to return.&lt;br /&gt;
*** The search returns nodes, which can be documents, elements, attributes, or text. Thus, a search doesn&#039;t have to return entire documents. Depending on the scope of your XPath statement, it may return entire documents, or one matching node from each document, or many matching nodes from each document.&lt;br /&gt;
** Y&#039;&#039;&#039;ou must include a cts query expression&#039;&#039;&#039; to filter the contents of nodes selected by the XPath expression. This allows you to search for specific content within specific nodes and return only those nodes that contain that content.&lt;br /&gt;
*** MarkLogic limits search results to words, phrases, values, and structures in the query that occur within the nodes specified by the XPath expression.&lt;br /&gt;
&lt;br /&gt;
* &lt;br /&gt;
** &lt;br /&gt;
*** If you want to return entire documents and search within specific elements and attributes, then the XPath expression should specify the root element and the query should use the element and element-attribute queries to limit where the search occurs. &lt;br /&gt;
*** If you want to return all the nodes selected by the XPath expression, you can use the empty query expression: &amp;lt;tt&amp;gt;cts:and-query(())&amp;lt;/tt&amp;gt;. &lt;br /&gt;
&lt;br /&gt;
* &lt;br /&gt;
** You may limit the search to specific forests. You may set options like unfiltered, faceted, unchecked, quality weight, relevance scoring method, and relevance trace.&lt;br /&gt;
** Use Cases:&lt;br /&gt;
*** A search can return entire documents whose contents match the XPath and query expressions.&lt;br /&gt;
*** A search can extract and return titles from documents as long as the contents of the titles match the XPath and query expressions.&lt;br /&gt;
*** A search can extract and return all the paragraphs from documents as long as the contents of the paragraphs match the XPath and query expressions.&lt;br /&gt;
** Notes:&lt;br /&gt;
*** There is no functional difference between searching entire documents and elements because an element has the same structure as document. Both may contain complex nested elements or both may simply contain a value. In both cases, MarkLogic retrieves entire documents. In the case of elements, it extracts the requested elements from each retrieved document.&lt;br /&gt;
*** Searching attributes, text nodes, and childless elements is similar to searching documents and elements with children — except the cts query cannot look for nested structures.&lt;br /&gt;
* [http://docs.marklogic.com/cts:contains cts:contains] is the second most important function because it returns true when a cts query finds at least one matching node in the nodes returned by an XPath expression (or a sequence of values). In other words, it returns true when at least one of the specified nodes &#039;&#039;contains&#039;&#039; the precise combination of words, phrases, values, structures, and/or triples in a cts query.&lt;br /&gt;
* NOTE: in the second example for [http://docs.marklogic.com/cts:not-query cts:not-query], it says cts:contains forces the constraint to happen in the filtering stage of the query. Is this always true for cts:contains, or is it only true in the example?&lt;br /&gt;
&lt;br /&gt;
=== Constructing a Query ===&lt;br /&gt;
You compose a query using cts query constructor functions. You then execute the query by passing it into &amp;lt;tt&amp;gt;cts:search, cts:contains, search:search&amp;lt;/tt&amp;gt;, and lexicon functions. MarkLogic has 30+ query constructors. They all end in &amp;quot;-query&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
==== Composite Query Constructors ====&lt;br /&gt;
The composite query constructors build up new queries from other queries, and queries can be nested within queries.&lt;br /&gt;
&lt;br /&gt;
* [http://docs.marklogic.com/cts:and-query cts:and-query] returns a query that intersects two or more sub-queries. &lt;br /&gt;
** You may optionally specify an &amp;quot;ordered&amp;quot; option that requires document contents to match sub-queries in the order they are listed; for example if the sub-queries are &amp;quot;To be&amp;quot; and &amp;quot;or not to be&amp;quot;, then the query will match documents that have the phrase &amp;quot;To be&amp;quot; before &amp;quot;or not to be&amp;quot;. The default is &amp;quot;unordered&amp;quot;, which allows each sub-query to match the content in any order that it occurs in the document.&lt;br /&gt;
** If you pass in the empty sequence, such as &amp;lt;tt&amp;gt;cts:and-query(())&amp;lt;/tt&amp;gt;, then it will match every document in the database.&lt;br /&gt;
* [http://docs.marklogic.com/cts:or-query cts:or-query] returns a query that unions two or more sub-queries.&lt;br /&gt;
* [http://docs.marklogic.com/cts:not-query cts:not-query] returns a query that subtracts one or more sub-queries.&lt;br /&gt;
** It works by taking the list of all documents in the database and subtracting the documents returned from its sub-queries. It returns all remaining documents. It does not filter documents returned from its sub-queries because filtering happens after all index resolution has completed, and &amp;lt;tt&amp;gt;cts:not-query &amp;lt;/tt&amp;gt;executes during index resolution. Thus, only if its sub-queries return accurate results (with no false-positives), then the results of &amp;lt;tt&amp;gt;cts:not-query&amp;lt;/tt&amp;gt; are accurate. Thus, it only produces accurate results when all its sub-queries are resolvable completely from indexes with no filtering required.&lt;br /&gt;
** &#039;&#039;&#039;Warning&#039;&#039;&#039;: &amp;lt;tt&amp;gt;cts:not-query &amp;lt;/tt&amp;gt;can be inaccurate. It can be missing some documents. This happens when one or more of its sub-queries require filtering (i.e. can&#039;t be resolved accurately using only indexes). When sub-queries require filtering, they may return false-positive matches. A false-positive match occurs when the indexes cannot determine for sure if a document matches; so MarkLogic includes the document just in case. As the last step in a query, MarkLogic opens all potentially matching documents and filters out false-positive matches. Thus, false-positives are not a match, they are a failed potential match. False positives can be prevented by writing sub-queries that are resolved completely by the indexes so that there is no need for filtering.&lt;br /&gt;
** Because &amp;lt;tt&amp;gt;cts:not-query &amp;lt;/tt&amp;gt;runs during index resolution (before filtering occurs), it subtracts out any false-positive matches returned by its sub-queries. False-positives should not be subtracted out. But MarkLogic doesn&#039;t know which documents are false-positives until filtering, and it can&#039;t do filtering during &amp;lt;tt&amp;gt;cts:not-query &amp;lt;/tt&amp;gt;because it is in the middle of doing index resolution. Thus, MarkLogic subtracts out false-positives and this causes &amp;lt;tt&amp;gt;cts:not-query &amp;lt;/tt&amp;gt;to return too few documents. If we prevent sub-queries from returning false-positives, &amp;lt;tt&amp;gt;cts:not-query &amp;lt;/tt&amp;gt;returns accurate results.&lt;br /&gt;
* [http://docs.marklogic.com/cts:and-not-query cts:and-not-query]&lt;br /&gt;
* [http://docs.marklogic.com/cts:element-query cts:element-query]&lt;br /&gt;
* [http://docs.marklogic.com/cts:document-fragment-query cts:document-fragment-query]&lt;br /&gt;
* [http://docs.marklogic.com/cts:locks-query cts:locks-query]&lt;br /&gt;
* [http://docs.marklogic.com/cts:properties-query cts:properties-query]&lt;br /&gt;
* [http://docs.marklogic.com/cts:near-query cts:near-query]&lt;br /&gt;
&lt;br /&gt;
== Training Resources for MarkLogic Search ==&lt;br /&gt;
* [http://developer.marklogic.com/blog/grokking-the-cts-api &amp;quot;Grokking the cts API&amp;quot;] is a great overview of MarkLogic&#039;s search and query capabilities.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;nowiki&amp;gt;[[Category: MarkLogic]]&amp;lt;/nowiki&amp;gt;&lt;/div&gt;</summary>
		<author><name>Bowersmt</name></author>
	</entry>
	<entry>
		<id>https://tech.churchofjesuschrist.org/wiki/index.php?title=MarkLogic_Query_and_Search&amp;diff=70584</id>
		<title>MarkLogic Query and Search</title>
		<link rel="alternate" type="text/html" href="https://tech.churchofjesuschrist.org/wiki/index.php?title=MarkLogic_Query_and_Search&amp;diff=70584"/>
		<updated>2014-11-19T07:01:10Z</updated>

		<summary type="html">&lt;p&gt;Bowersmt: Updated cts:not-query&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[[MarkLogic|« Back to MarkLogic]]&lt;br /&gt;
&lt;br /&gt;
== Searching and Querying MarkLogic ==&lt;br /&gt;
Indexes are central to everything you do in MarkLogic.  They are central to how MarkLogic stores data, scales massively, and processes data quickly. They are central to how you develop because you have to use MarkLogic&#039;s indexes to query and search documents. You have to understand how MarkLogic&#039;s indexes work to be able to create fast queries. And you have to know how to model document structure to work best with indexes.&lt;br /&gt;
&lt;br /&gt;
=== How does MarkLogic compare to a relational database? ===&lt;br /&gt;
A document in MarkLogic is very much like a row in a relational database, and a document type ties documents together like a table ties rows together. MarkLogic collections group documents together in any way you want. Collections are like views in a relational database, which group together a filtered set of rows from one or more tables, but collections do not join and merge document content and views cannot arbitrarily include any row from any table. A document in MarkLogic can have a flat structure like a relational table, or it can contain complex nestings of data.  Each nesting of data in a document represents another table in a relational database. For example, a single document in MarkLogic may represent many relational tables, and how they are nested represents their one-to-one, many-to-one, and many-to-many relationships.  &lt;br /&gt;
&lt;br /&gt;
Both MarkLogic and relational databases use indexes to resolve queries without having to scan through all documents or rows. MarkLogic indexes are designed to find any word, phrase, value, element, or element structure -- no matter where it occurs in document structure, no matter how many times it occurs within a document, and no matter what type of document contains it. For example, you can search for and return a &amp;lt;title&amp;gt; element and MarkLogic will return the contents of all &amp;lt;title&amp;gt; elements it finds — even if &amp;lt;title&amp;gt; elements are in different types of documents. This is similar to doing a union query across multiple tables in relational databases. &lt;br /&gt;
&lt;br /&gt;
MarkLogic indexes also let you search for words, phrases, values, elements, or element structures in very specific locations, such as in only certain types of documents or within certain document structures, or in specific collections or folders. For example, you can search for and return all &amp;lt;title&amp;gt; elements that are found in the header section of poetry documents in the Shakespeare and Tennyson collections. &lt;br /&gt;
&lt;br /&gt;
MarkLogic is not designed for joining documents like a relational database.  A relational join searches for matching values across two or more tables and then merges matching rows into a single row. This can be done in MarkLogic, but you have to write advanced code to iterate through query results to match values across different document types, and merge matching documents into a single document. Also since MarkLogic documents are often nested structures, you can&#039;t simply merge them, you have to copy nested content from one document into a specific nested location in another.&lt;br /&gt;
&lt;br /&gt;
Unlike relational databases, MarkLogic can&#039;t do full table scans; queries must use indexes. In contrast, relational databases often use a full table scan to retrieve every row in a table. A rule of thumb in relational databases is that it is faster to directly read in &#039;&#039;all&#039;&#039; the rows when a query accesses more than roughly 25% of the rows. This is because relational databases use variations of the B-Tree index, which requires 3-4 random IOs to find one row and 1 IO to retrieve the row: this is 4-5 total IOs per row.  B-Tree indexes work best for single row lookups, but they become increasingly costly the more rows they retrieve. If an index has to lookup 25% of its rows with 4 IOs per row, the database will do the same amount of IO if it reads in all of the rows (1 IO per row). Since sequential IO on disks is faster than random IO, relational databases prefer full table scans when accessing more than about 25% of rows in a table. On analytical data warehouses, full table scans are always preferred.  &lt;br /&gt;
&lt;br /&gt;
In addition, a relational database [https://docs.oracle.com/database/121/TGSQL/tgsql_optop.htm#TGSQL234 often directly scans through index data] rather than stepping through its B-Tree structure. Databases use a variety of index scans: full scans, range scans, skip scans, join scans, etc. This is index and table records are stored sequentially on disk. This often makes it faster to take advantage of the speed of sequential disk IO and directly load all index or table rows into RAM and process them in RAM; as opposed to walking a b-tree structure and doing multiple slow random IOs to retrieve each record. For the same reason, row and index scans work well in columnar NoSQL databases.&lt;br /&gt;
&lt;br /&gt;
=== Why do MarkLogic queries have to use Indexes? ===&lt;br /&gt;
To maximize parallelism and to spread processing throughout a cluster, MarkLogic spreads documents across the cluster. MarkLogic automatically creates multiple shards per server and spreads them across all the servers in the cluster. Documents are placed in a shard in the order they are created or modified; thus, documents of all types may be randomly intermixed in a shard. Since a shard is not organized by document type, doing a sequential scan to resolve a query would require retrieving and processing all documents in the database. Full scans are not practical in MarkLogic. All queries and searches need to use indexes. For this reason, MarkLogic automatically indexes almost everything. You can also create additional specialized indexes.  MarkLogic indexes are not B-Tree indexes; they are designed to be sharded and queried in parallel across stands, forests, and a database cluster that spans many servers.&lt;br /&gt;
&lt;br /&gt;
=== How does MarkLogic scale horizontally? ===&lt;br /&gt;
Documents in MarkLogic belong to a database. Within a database are one or more servers.  Each server may contain zero or more &amp;quot;forests&amp;quot;. Within each forest are one or more &amp;quot;stands&amp;quot;. Within each stand are one or more &amp;quot;trees&amp;quot;. A document is hierarchical so it is called a &amp;quot;tree&amp;quot;.  (MarkLogic uses the terms &amp;quot;stand&amp;quot; and &amp;quot;forest&amp;quot; instead of &amp;quot;shard&amp;quot;, but they have the same meaning.) &lt;br /&gt;
&lt;br /&gt;
A client contacts one of the servers in a MarkLogic cluster and initiates a query or search. Because MarkLogic communicates through REST web services, a load balancer can spread requests across the servers in a MarkLogic cluster.  The initiating server does the following&lt;br /&gt;
#It validates the query request from the client&lt;br /&gt;
#It parses and optimizes the query &lt;br /&gt;
#It sends the query to all servers that have forests in the database&lt;br /&gt;
##Each server sends it to its forests &lt;br /&gt;
##Each forest sends it to each stand &lt;br /&gt;
##Each stand uses its indexes to find matching documents&lt;br /&gt;
###All stands and forests query the indexes in parallel&lt;br /&gt;
##Forests combine the matching document IDs from all their stands&lt;br /&gt;
##Forests sort the matching document IDs (in relevance score order or value order)&lt;br /&gt;
##When complete, each forest returns a sorted iterator to the initiating server&lt;br /&gt;
#When each forest has returned an iterator&lt;br /&gt;
#It walks the sorted iterators from all the forests and combines the results in sorted &lt;br /&gt;
#It retrieves matching documents from its &#039;&#039;Expanded Tree Cache&#039;&#039; or from the forests when documents are not cached&lt;br /&gt;
##forests retrieve documents from their &#039;&#039;Compressed Tree Cache&#039;&#039; or from disk when documents are not cached&lt;br /&gt;
#It filters returned documents to remove false positive matches &lt;br /&gt;
#It optionally transforms documents &lt;br /&gt;
##It creates new documents by extracting matching elements, changing structure, changing file format, etc.&lt;br /&gt;
#It returns all matching (optionally transformed) documents to the requester&lt;br /&gt;
#It saves resulting document IDs when paging query results, so it can return subsequent pages of matching documents in subsequent requests&lt;br /&gt;
&lt;br /&gt;
The initiating server&#039;s process is CPU intensive, serialized, and blocks while waiting on forests. To prevent this from being a bottleneck to the cluster, you can dedicate nodes in the cluster to do nothing but evaluate queries. These are called e-nodes (evaluation nodes). These nodes don&#039;t hold data. If they held data, the &#039;&#039;serialized&#039;&#039; evaluation process would compete with the &#039;&#039;parallel&#039;&#039; index matching process.  Instead e-nodes are dedicated to validating, parsing, sorting, filtering, transforming, and paginating documents. They cache documents in the &#039;&#039;Expanded Tree Cache&#039;&#039; to minimize the number of documents they have to retrieve from data nodes (d-nodes). D-nodes only do parallel index processing and sorting. They cache documents in their &#039;&#039;Compressed Tree Cache&#039;&#039; to reduce disk IO. &lt;br /&gt;
&lt;br /&gt;
=== How do you optimize a MarkLogic cluster to run queries faster? ===&lt;br /&gt;
*E-nodes and d-nodes can be scaled independently to match the load. &lt;br /&gt;
*You can optimize an e-node by minimizing its &#039;&#039;Compressed Tree Cache&#039;&#039; and maximizing its &#039;&#039;Expanded Tree Cache&#039;&#039;. An e-node needs a big &#039;&#039;Expanded Tree Cache&#039;&#039; so it doesn&#039;t have to retrieve as many documents from d-nodes. An e-node doesn&#039;t need a &#039;&#039;Compressed Tree Cache&#039;&#039; because it doesn&#039;t have any data.&lt;br /&gt;
*You can optimize a d-node by doing the opposite of the e-node: maximize the &#039;&#039;Compressed Tree Cache&#039;&#039; and minimize the &#039;&#039;Expanded Tree Cache&#039;&#039;. You can also optimize d-nodes by making sure each d-node runs on similar hardware and that each forest has a similar number of documents. This is important because all forests process queries in parallel and the slowest forest holds up each query: e-nodes have to wait until the slowest forest finishes.&lt;br /&gt;
*You can optimize a query by making it unfiltered.&lt;br /&gt;
**This means it is completely resolved by the indexes. Because no filtering is required, the initiating server doesn&#039;t have to verify that documents match.&lt;br /&gt;
*You can optimize a query by eliminating false positives.  &lt;br /&gt;
**False positives occur when a query identifies a possible match for a document, but it cannot prove it is a match until the filtering process opens the document and verifies it. &lt;br /&gt;
**False positives happen because MarkLogic only partially indexes certain document items. MarkLogic cannot index everything because it would take too much time and space. For example, MarkLogic has a structure index. It indexes relationships between elements in a document.  MarkLogic cannot afford to index each element&#039;s path from itself to every other element. MarkLogic compromises on indexing only parent/child relationships. This is effective in eliminating most non-matching documents, but it can produce false positives.  The only way to know if a document is an &#039;&#039;exact&#039;&#039; match, MarkLogic must open the document and verify it.&lt;br /&gt;
**For example, suppose a query searches for the following path: &amp;lt;br&amp;gt;&amp;lt;code&amp;gt;books/poetry/poem&amp;lt;/code&amp;gt;&amp;lt;br&amp;gt; The structure index will match documents containing books/poetry and poetry/poem. The resulting documents are a probable match, but could contain false positives, such as &amp;lt;br&amp;gt;&amp;lt;code&amp;gt;books/poetry/fantasy/poetry/poem&amp;lt;/code&amp;gt;.&lt;br /&gt;
**You can eliminate false positive structures queries by giving elements unique names. They are  unique no matter where in they are in the structure and they are more self-descriptive.  Instead of naming an element &amp;quot;line&amp;quot; which can mean many things, you can use the precise name  &amp;quot;poemTextLine&amp;quot;. &lt;br /&gt;
*You can optimize a query by greatly limiting how many documents it matches. Design each query to return as few documents as possible. &lt;br /&gt;
**It is expensive to transmit documents. Matching documents have to travel from stands to forests to the initiating server, and to the requester. &lt;br /&gt;
**It is expensive to process documents on the initiating server and the requester. &lt;br /&gt;
**It takes processing time on d-nodes to compare lists of document IDs. The fewer the matching document IDs in one part of the query, the faster the entire query runs. &lt;br /&gt;
**The more matching document IDs, the more work MarkLogic has to do in a d-node to compare, union, intersect, and subract them from matching document IDs returned by other parts of the query. &lt;br /&gt;
**The more matching document IDs, the more sorting MarkLogic has to do in the stands, forests, and initiating server.&lt;br /&gt;
&lt;br /&gt;
=== How does a MarkLogic query compare to map/reduce? ===&lt;br /&gt;
A MarkLogic query or search is similar to map/reduce.  When you query or search for documents in a database, MarkLogic spreads the work across all the servers to be executed in parallel. This is like a &#039;&#039;map&#039;&#039; process because indexes filter out non-matching documents by combining term, range, and semantic indexes according to the query map. The results are then &#039;&#039;reduced&#039;&#039; at the forest level and again at the database level and again at the initiating server. This parallel division of responsibilities enables MarkLogic to scale.&lt;br /&gt;
&lt;br /&gt;
== Term, Range, and Semantic Indexes ==&lt;br /&gt;
MarkLogic indexes are not B-Tree indexes. MarkLogic uses &#039;&#039;&#039;term&#039;&#039;&#039;, &#039;&#039;&#039;range&#039;&#039;&#039;, and &#039;&#039;&#039;semantic&#039;&#039;&#039; indexes. &lt;br /&gt;
*&#039;&#039;&#039;A term index&#039;&#039;&#039; associates a term with every document that contains the term.  For example, in a word index, every word in the database is stored in the index. Associated with each word in the index is a list of each document ID that contains the term.  &lt;br /&gt;
*&#039;&#039;&#039;A range index&#039;&#039;&#039; is a double term index: it contains each term and all document IDs that contain that term, and it contains each document ID and all the terms that are in the document.&lt;br /&gt;
*&#039;&#039;&#039;A semantic index&#039;&#039;&#039; is similar to a range index but it is optimized to store triples (three pieces of data: subject, object, and predicate).&lt;br /&gt;
&lt;br /&gt;
Term indexes are fast. Give the index a term, and with one lookup, it returns &#039;&#039;all&#039;&#039; documents that contain the term. Term indexes are memory mapped files. They run in RAM unless you run out of RAM and then firmware in the CPU efficiently swaps them to and from disk. Thus, it is best to have enough RAM in a MarkLogic server to contain all indexes in memory.&lt;br /&gt;
&lt;br /&gt;
Unlike B-Tree indexes, term indexes are easily sharded within and between servers. MarkLogic takes advantage of this to run queries in parallel within and across servers. This is how MarkLogic can scale to billions of documents and still return queries and searches in milliseconds.&lt;br /&gt;
&lt;br /&gt;
When documents are inserted or updated, MarkLogic indexes them in RAM (as well as appends the changes to a journal on disk). When documents in RAM start to consume too much RAM, MarkLogic writes them to disk as a &amp;quot;stand&amp;quot; in a &amp;quot;forest&amp;quot; and starts creating a new &amp;quot;stand&amp;quot; in RAM.  &lt;br /&gt;
&lt;br /&gt;
When you query or search for documents, MarkLogic goes to the indexes in the stands (which are cached in RAM) and evaluates the query in parallel. Each stand index returns a list of document IDs (a list of numbers) that match the query. MarkLogic takes the document IDs returned by each stand and merges them into a final list of document IDs, which it uses to retrieve the documents from cache or disk. This works well because computers are very fast at sort merging lists of numbers.&lt;br /&gt;
&lt;br /&gt;
MarkLogic uses the same indexes for both queries and searches. This allows you to combine search and query expressions. The main difference between search and query is how documents are sorted: searches sort by relevance and queries sort by values. Another difference is that queries tend to use value indexes and searches tend to use word and phrase indexes. &lt;br /&gt;
&lt;br /&gt;
=== What specific indexes does MarkLogic have? ===&lt;br /&gt;
MarkLogic uses indexes to extract words, values, structures, and links out of documents. An index is an altered view of a document. It enables you to search and query for documents &amp;lt;br&amp;gt;&#039;&#039;&#039;as if they contained only:&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
*&#039;&#039;&#039;Words:&#039;&#039;&#039; a flat set of words without structure, such as &amp;lt;br&amp;gt;&amp;lt;code&amp;gt;[&amp;quot;Mary&amp;quot;, &amp;quot;had&amp;quot;, &amp;quot;a&amp;quot;, &amp;quot;little&amp;quot;, &amp;quot;lamb&amp;quot;]&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
*&#039;&#039;&#039;Phrases:&#039;&#039;&#039; a flat set of phrases without structure, such as &amp;lt;br&amp;gt;&amp;lt;code&amp;gt;[&amp;quot;Mary had&amp;quot;, &amp;quot;had a&amp;quot;, &amp;quot;a little&amp;quot;, &amp;quot;little lamb&amp;quot;]&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
*&#039;&#039;&#039;Elements:&#039;&#039;&#039; a flat set of elements without values, such as &amp;lt;br&amp;gt;&amp;lt;code&amp;gt;[&amp;quot;poem&amp;quot;, &amp;quot;text&amp;quot;, &amp;quot;line&amp;quot;]&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
*&#039;&#039;&#039;Element-values:&#039;&#039;&#039; a flat set of elements with string values, such as &amp;lt;br&amp;gt;&amp;lt;code&amp;gt;&amp;quot;line&amp;quot;: &amp;quot;Mary had a little lamb&amp;quot;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
*&#039;&#039;&#039;Element-words:&#039;&#039;&#039; a flat set of elements with words, such as &amp;lt;br&amp;gt;&amp;lt;code&amp;gt;&amp;quot;line&amp;quot;: [&amp;quot;Mary&amp;quot;, &amp;quot;had&amp;quot;, &amp;quot;a&amp;quot;, &amp;quot;little&amp;quot;, &amp;quot;lamb&amp;quot;]&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
*&#039;&#039;&#039;Element-phrases:&#039;&#039;&#039; a flat set of elements with phrases, such as &amp;lt;br&amp;gt;&amp;lt;code&amp;gt;&amp;quot;line&amp;quot;: [&amp;quot;Mary had&amp;quot;, &amp;quot;had a&amp;quot;, &amp;quot;a little&amp;quot;, &amp;quot;little lamb&amp;quot;]&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
*&#039;&#039;&#039;Element-value lexicon:&#039;&#039;&#039; a flat set of elements with typed values, such as &amp;lt;br&amp;gt;&amp;lt;code&amp;gt;&amp;quot;lineSequence&amp;quot;: 3&amp;lt;/code&amp;gt;&amp;lt;br&amp;gt; or a list, count, or co-occurrence of element values scoped to a database, set of documents, or one document.&lt;br /&gt;
&lt;br /&gt;
*&#039;&#039;&#039;XPath-structure-value lexicon:&#039;&#039;&#039; a flat set of hierarchical elements with typed values, such as &amp;lt;br&amp;gt;&amp;lt;code&amp;gt;poem.text.line.lineSequence: 3&amp;lt;/code&amp;gt;&amp;lt;br&amp;gt; or a list, count, or co-occurrence of hierarchical element values scoped to a database, set of documents, or one document.&lt;br /&gt;
&lt;br /&gt;
*&#039;&#039;&#039;XPath-structure:&#039;&#039;&#039;hierarchical structures without values, such as &amp;lt;br&amp;gt;&amp;lt;code&amp;gt;poem.text.line&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
*&#039;&#039;&#039;XPath-structure-words:&#039;&#039;&#039; hierarchical structures with words, such as &amp;lt;br&amp;gt;&amp;lt;code&amp;gt;poem.text.line: [&amp;quot;Mary&amp;quot;, &amp;quot;had&amp;quot;, &amp;quot;a&amp;quot;, &amp;quot;little&amp;quot;, &amp;quot;lamb&amp;quot;]&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
*&#039;&#039;&#039;XPath-structure-phrases:&#039;&#039;&#039; hierarchical structures with phrases, such as &amp;lt;br&amp;gt;&amp;lt;code&amp;gt;poem.text.line: [&amp;quot;Mary had&amp;quot;, &amp;quot;had a&amp;quot;, &amp;quot;a little&amp;quot;, &amp;quot;little lamb&amp;quot;]&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
*&#039;&#039;&#039;XPath-structure-values:&#039;&#039;&#039; hierarchical structures with values, such as &amp;lt;br&amp;gt;&amp;lt;code&amp;gt;poem.text.line: &amp;quot;Mary had a little lamb&amp;quot;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
*&#039;&#039;&#039;RDF document links&#039;&#039;&#039; to other documents, such as &amp;lt;br&amp;gt;&amp;lt;code&amp;gt;{&amp;quot;subject&amp;quot;: &amp;quot;http://example.org/documents/thisDoc&amp;quot;, &amp;lt;br&amp;gt;&amp;quot;predicate&amp;quot;: &amp;quot;http://example.org/predicates/relatesSomehowTo&amp;quot;, &amp;lt;br&amp;gt;&amp;quot;object&amp;quot;: &amp;quot;http://example.org/documents/thatDoc&amp;quot;}&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
*&#039;&#039;&#039;RDF abstract links&#039;&#039;&#039; to other abstract concepts, such as &amp;lt;br&amp;gt;&amp;lt;code&amp;gt;{&amp;quot;subject&amp;quot;: &amp;quot;http://example.org/documents/thisDoc&amp;quot;, &amp;lt;br&amp;gt;&amp;quot;predicate&amp;quot;: &amp;quot;http://example.org/predicates/relatesSomehowTo&amp;quot;, &amp;lt;br&amp;gt;&amp;quot;object&amp;quot;: &amp;quot;http://example.org/documents/someConceptWithNoDocumentAtTheURI&amp;quot;}&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
*&#039;&#039;&#039;RDF data links&#039;&#039;&#039; to data, such as &amp;lt;br&amp;gt;&amp;lt;code&amp;gt;{&amp;quot;subject&amp;quot;: &amp;quot;http://example.org/documents/thisDoc&amp;quot;, &amp;lt;br&amp;gt;&amp;quot;predicate&amp;quot;: &amp;quot;http://example.org/predicates/ageInYears&amp;quot;, &amp;lt;br&amp;gt;&amp;quot;object&amp;quot;: 12}&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
MarkLogic can combine any of these indexes in any way to find matching documents.  It can sort the result by relevance or by value. &lt;br /&gt;
&lt;br /&gt;
Search and query expressions are fully composable; i.e. they can be nested inside each other and combined using AND, OR, and NOT expressions.&lt;br /&gt;
&lt;br /&gt;
== Search Functions in MarkLogic ==&lt;br /&gt;
=== Executing a Search ===&lt;br /&gt;
*&#039;&#039;&#039;&amp;lt;code&amp;gt;[http://docs.marklogic.com/cts:search cts:search]&amp;lt;/code&amp;gt;&#039;&#039;&#039; is the most important function because it executes a search and returns matching nodes. &lt;br /&gt;
**&#039;&#039;&#039;You must include an XPath expression&#039;&#039;&#039; to define which nodes to &#039;&#039;search&#039;&#039; within and to &#039;&#039;return&#039;&#039;. &lt;br /&gt;
***The search returns &#039;&#039;nodes&#039;&#039;, which can be documents, elements, attributes, or text. Thus, a search doesn&#039;t have to return entire documents. Depending on the scope of your XPath statement, it may return entire documents, or one matching node from each document, or many matching nodes from each document.  &lt;br /&gt;
**&#039;&#039;&#039;You must include a cts query expression&#039;&#039;&#039; to filter the contents of &#039;&#039;nodes&#039;&#039; selected by the XPath expression. This allows you to search for specific content within specific nodes and return only those nodes that contain that content. &lt;br /&gt;
***MarkLogic limits search results to words, phrases, values, and structures in the query that occur within the nodes specified by the XPath expression. &lt;br /&gt;
***If you want to return entire documents and search within specific elements and attributes, then the XPath expression should specify the root element and the query should use the element and  element-attribute queries to limit where the search occurs.&lt;br /&gt;
***If you want to return all the nodes selected by the XPath expression, you can use the empty query expression: &amp;lt;code&amp;gt;cts:and-query(())&amp;lt;/code&amp;gt;.&lt;br /&gt;
**You may limit the search to specific forests. You may set options like unfiltered, faceted, unchecked, quality weight, relevance scoring method, and relevance trace.&lt;br /&gt;
**Use Cases:&lt;br /&gt;
***A search can return entire documents whose contents match the XPath and query expressions.&lt;br /&gt;
***A search can extract and return titles from documents as long as the contents of the titles match the XPath and query expressions.&lt;br /&gt;
***A search can extract and return all the paragraphs from documents as long as the contents of the paragraphs match the XPath and query expressions.&lt;br /&gt;
**Notes:&lt;br /&gt;
***There is no functional difference between searching entire documents and elements because an element has the same structure as document.  Both may contain complex nested elements or both may simply contain a value. In both cases, MarkLogic retrieves entire documents. In the case of elements, it extracts the requested elements from each retrieved document.&lt;br /&gt;
***Searching attributes, text nodes, and childless elements is similar to searching documents and elements with children — except the cts query cannot look for nested structures.&lt;br /&gt;
&lt;br /&gt;
*&#039;&#039;&#039;&amp;lt;code&amp;gt;[http://docs.marklogic.com/cts:contains cts:contains]&amp;lt;/code&amp;gt;&#039;&#039;&#039; is the second most important function because it returns true when a cts query finds at least one matching node in the nodes returned by an XPath expression (or a sequence of values). In other words, it returns true when at least one of the specified nodes &#039;&#039;&#039;contains&#039;&#039;&#039; the precise combination of words, phrases, values, structures, and/or triples in a cts query. &lt;br /&gt;
**NOTE: in the second example for &amp;lt;code&amp;gt;[http://docs.marklogic.com/cts:not-query cts:not-query]&amp;lt;/code&amp;gt;, it says cts:contains forces the constraint to happen in the filtering stage of the query. Is this always true for cts:contains, or is it only true in the example?&lt;br /&gt;
&lt;br /&gt;
=== Constructing a Query ===&lt;br /&gt;
You compose a query using cts query constructor functions. You then execute the query by passing it into &amp;lt;code&amp;gt;cts:search, cts:contains, search:search&amp;lt;/code&amp;gt;, and lexicon functions. MarkLogic has 30+ query constructors. They all end in &#039;&#039;&#039;&amp;quot;-query&amp;quot;&#039;&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
==== Composite Query Constructors ====&lt;br /&gt;
The composite query constructors build up new queries from other queries, and queries can be nested within queries.&lt;br /&gt;
&lt;br /&gt;
*&#039;&#039;&#039;&amp;lt;code&amp;gt;[http://docs.marklogic.com/cts:and-query cts:and-query]&amp;lt;/code&amp;gt;&#039;&#039;&#039; returns a query that intersects two or more sub-queries. &lt;br /&gt;
**You may optionally specify an &amp;quot;ordered&amp;quot; option that requires document contents to match sub-queries in the order they are listed; for example if the sub-queries are &amp;quot;To be&amp;quot; and &amp;quot;or not to be&amp;quot;, then the query will match documents that have the phrase &amp;quot;To be&amp;quot; &#039;&#039;before&#039;&#039; &amp;quot;or not to be&amp;quot;. The default is &amp;quot;unordered&amp;quot;, which allows each sub-query to match the content in any order that it occurs in the document.  &lt;br /&gt;
**If you pass in the empty sequence, such as &amp;lt;code&amp;gt;cts:and-query(())&amp;lt;/code&amp;gt;, then it will match every document in the database.&lt;br /&gt;
&lt;br /&gt;
*&#039;&#039;&#039;&amp;lt;code&amp;gt;[http://docs.marklogic.com/cts:or-query cts:or-query]&amp;lt;/code&amp;gt;&#039;&#039;&#039; returns a query that unions two or more sub-queries.&lt;br /&gt;
&lt;br /&gt;
*&#039;&#039;&#039;&amp;lt;code&amp;gt;[http://docs.marklogic.com/cts:not-query cts:not-query]&amp;lt;/code&amp;gt;&#039;&#039;&#039; returns a query that subtracts one or more sub-queries.&lt;br /&gt;
**It works by taking the list of all documents in the database and subtracting the documents returned from its sub-queries. It returns all remaining documents. It does not filter documents returned from its sub-queries because filtering happens after all index resolution has completed, and &amp;lt;code&amp;gt;cts:not-query&amp;lt;/code&amp;gt; executes during index resolution. Thus, only if its sub-queries return accurate results (with no false-positives), then the results of &amp;lt;code&amp;gt;cts:not-query&amp;lt;/code&amp;gt; are accurate. Thus, it only produces accurate results when all its sub-queries are resolvable completely from indexes with no filtering required.&lt;br /&gt;
**&#039;&#039;&#039;Warning:&#039;&#039;&#039; cts:not-query can be inaccurate. It can be missing some documents. This happens when one or more of its sub-queries require filtering (i.e. can&#039;t be resolved accurately using only indexes).  When sub-queries require filtering, they may return false-positive matches. A false-positive match occurs when the indexes cannot determine for sure if a document matches; so MarkLogic includes the document just in case. As the last step in a query, MarkLogic opens all potentially matching documents and filters out false-positive matches. Thus, false-positives are not a match, they are a failed potential match. False positives can be prevented by writing sub-queries that are resolved completely by the indexes so that there is no need for filtering.&lt;br /&gt;
***Because &amp;lt;code&amp;gt;cts:not-query&amp;lt;/code&amp;gt; runs during index resolution (before filtering occurs), it subtracts out any false-positive matches returned by its sub-queries. False-positives should not be subtracted out. But MarkLogic doesn&#039;t know which documents are false-positives until filtering, and it can&#039;t do filtering during &amp;lt;code&amp;gt;cts:not-query&amp;lt;/code&amp;gt; because it is in the middle of doing index resolution. Thus, MarkLogic subtracts out false-positives and this causes &amp;lt;code&amp;gt;cts:not-query&amp;lt;/code&amp;gt; to return too few documents. If we prevent sub-queries from returning false-positives, &amp;lt;code&amp;gt;cts:not-query&amp;lt;/code&amp;gt; returns accurate results.&lt;br /&gt;
&lt;br /&gt;
*&#039;&#039;&#039;&amp;lt;code&amp;gt;[http://docs.marklogic.com/cts:and-not-query cts:and-not-query]&amp;lt;/code&amp;gt;&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
*&#039;&#039;&#039;&amp;lt;code&amp;gt;[http://docs.marklogic.com/cts:element-query cts:element-query]&amp;lt;/code&amp;gt;&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
*&#039;&#039;&#039;&amp;lt;code&amp;gt;[http://docs.marklogic.com/cts:document-fragment-query cts:document-fragment-query]&amp;lt;/code&amp;gt;&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
*&#039;&#039;&#039;&amp;lt;code&amp;gt;[http://docs.marklogic.com/cts:locks-query cts:locks-query]&amp;lt;/code&amp;gt;&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
*&#039;&#039;&#039;&amp;lt;code&amp;gt;[http://docs.marklogic.com/cts:properties-query cts:properties-query]&amp;lt;/code&amp;gt;&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
*&#039;&#039;&#039;&amp;lt;code&amp;gt;[http://docs.marklogic.com/cts:near-query cts:near-query]&amp;lt;/code&amp;gt;&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Training Resources for MarkLogic Search ==&lt;br /&gt;
* [http://developer.marklogic.com/blog/grokking-the-cts-api &amp;quot;Grokking the cts API&amp;quot;] is a great overview of MarkLogic&#039;s search and query capabilities.&lt;br /&gt;
&lt;br /&gt;
[[Category: MarkLogic]]&lt;/div&gt;</summary>
		<author><name>Bowersmt</name></author>
	</entry>
	<entry>
		<id>https://tech.churchofjesuschrist.org/wiki/index.php?title=MarkLogic_Query_and_Search&amp;diff=70583</id>
		<title>MarkLogic Query and Search</title>
		<link rel="alternate" type="text/html" href="https://tech.churchofjesuschrist.org/wiki/index.php?title=MarkLogic_Query_and_Search&amp;diff=70583"/>
		<updated>2014-11-19T06:18:40Z</updated>

		<summary type="html">&lt;p&gt;Bowersmt: Updated cts:not-query&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[[MarkLogic|« Back to MarkLogic]]&lt;br /&gt;
&lt;br /&gt;
== Searching and Querying MarkLogic ==&lt;br /&gt;
Indexes are central to everything you do in MarkLogic.  They are central to how MarkLogic stores data, scales massively, and processes data quickly. They are central to how you develop because you have to use MarkLogic&#039;s indexes to query and search documents. You have to understand how MarkLogic&#039;s indexes work to be able to create fast queries. And you have to know how to model document structure to work best with indexes.&lt;br /&gt;
&lt;br /&gt;
=== How does MarkLogic compare to a relational database? ===&lt;br /&gt;
A document in MarkLogic is very much like a row in a relational database, and a document type ties documents together like a table ties rows together. MarkLogic collections group documents together in any way you want. Collections are like views in a relational database, which group together a filtered set of rows from one or more tables, but collections do not join and merge document content and views cannot arbitrarily include any row from any table. A document in MarkLogic can have a flat structure like a relational table, or it can contain complex nestings of data.  Each nesting of data in a document represents another table in a relational database. For example, a single document in MarkLogic may represent many relational tables, and how they are nested represents their one-to-one, many-to-one, and many-to-many relationships.  &lt;br /&gt;
&lt;br /&gt;
Both MarkLogic and relational databases use indexes to resolve queries without having to scan through all documents or rows. MarkLogic indexes are designed to find any word, phrase, value, element, or element structure -- no matter where it occurs in document structure, no matter how many times it occurs within a document, and no matter what type of document contains it. For example, you can search for and return a &amp;lt;title&amp;gt; element and MarkLogic will return the contents of all &amp;lt;title&amp;gt; elements it finds — even if &amp;lt;title&amp;gt; elements are in different types of documents. This is similar to doing a union query across multiple tables in relational databases. &lt;br /&gt;
&lt;br /&gt;
MarkLogic indexes also let you search for words, phrases, values, elements, or element structures in very specific locations, such as in only certain types of documents or within certain document structures, or in specific collections or folders. For example, you can search for and return all &amp;lt;title&amp;gt; elements that are found in the header section of poetry documents in the Shakespeare and Tennyson collections. &lt;br /&gt;
&lt;br /&gt;
MarkLogic is not designed for joining documents like a relational database.  A relational join searches for matching values across two or more tables and then merges matching rows into a single row. This can be done in MarkLogic, but you have to write advanced code to iterate through query results to match values across different document types, and merge matching documents into a single document. Also since MarkLogic documents are often nested structures, you can&#039;t simply merge them, you have to copy nested content from one document into a specific nested location in another.&lt;br /&gt;
&lt;br /&gt;
Unlike relational databases, MarkLogic can&#039;t do full table scans; queries must use indexes. In contrast, relational databases often use a full table scan to retrieve every row in a table. A rule of thumb in relational databases is that it is faster to directly read in &#039;&#039;all&#039;&#039; the rows when a query accesses more than roughly 25% of the rows. This is because relational databases use variations of the B-Tree index, which requires 3-4 random IOs to find one row and 1 IO to retrieve the row: this is 4-5 total IOs per row.  B-Tree indexes work best for single row lookups, but they become increasingly costly the more rows they retrieve. If an index has to lookup 25% of its rows with 4 IOs per row, the database will do the same amount of IO if it reads in all of the rows (1 IO per row). Since sequential IO on disks is faster than random IO, relational databases prefer full table scans when accessing more than about 25% of rows in a table. On analytical data warehouses, full table scans are always preferred.  &lt;br /&gt;
&lt;br /&gt;
In addition, a relational database [https://docs.oracle.com/database/121/TGSQL/tgsql_optop.htm#TGSQL234 often directly scans through index data] rather than stepping through its B-Tree structure. Databases use a variety of index scans: full scans, range scans, skip scans, join scans, etc. This is index and table records are stored sequentially on disk. This often makes it faster to take advantage of the speed of sequential disk IO and directly load all index or table rows into RAM and process them in RAM; as opposed to walking a b-tree structure and doing multiple slow random IOs to retrieve each record. For the same reason, row and index scans work well in columnar NoSQL databases.&lt;br /&gt;
&lt;br /&gt;
=== Why do MarkLogic queries have to use Indexes? ===&lt;br /&gt;
To maximize parallelism and to spread processing throughout a cluster, MarkLogic spreads documents across the cluster. MarkLogic automatically creates multiple shards per server and spreads them across all the servers in the cluster. Documents are placed in a shard in the order they are created or modified; thus, documents of all types may be randomly intermixed in a shard. Since a shard is not organized by document type, doing a sequential scan to resolve a query would require retrieving and processing all documents in the database. Full scans are not practical in MarkLogic. All queries and searches need to use indexes. For this reason, MarkLogic automatically indexes almost everything. You can also create additional specialized indexes.  MarkLogic indexes are not B-Tree indexes; they are designed to be sharded and queried in parallel across stands, forests, and a database cluster that spans many servers.&lt;br /&gt;
&lt;br /&gt;
=== How does MarkLogic scale horizontally? ===&lt;br /&gt;
Documents in MarkLogic belong to a database. Within a database are one or more servers.  Each server may contain zero or more &amp;quot;forests&amp;quot;. Within each forest are one or more &amp;quot;stands&amp;quot;. Within each stand are one or more &amp;quot;trees&amp;quot;. A document is hierarchical so it is called a &amp;quot;tree&amp;quot;.  (MarkLogic uses the terms &amp;quot;stand&amp;quot; and &amp;quot;forest&amp;quot; instead of &amp;quot;shard&amp;quot;, but they have the same meaning.) &lt;br /&gt;
&lt;br /&gt;
A client contacts one of the servers in a MarkLogic cluster and initiates a query or search. Because MarkLogic communicates through REST web services, a load balancer can spread requests across the servers in a MarkLogic cluster.  The initiating server does the following&lt;br /&gt;
#It validates the query request from the client&lt;br /&gt;
#It parses and optimizes the query &lt;br /&gt;
#It sends the query to all servers that have forests in the database&lt;br /&gt;
##Each server sends it to its forests &lt;br /&gt;
##Each forest sends it to each stand &lt;br /&gt;
##Each stand uses its indexes to find matching documents&lt;br /&gt;
###All stands and forests query the indexes in parallel&lt;br /&gt;
##Forests combine the matching document IDs from all their stands&lt;br /&gt;
##Forests sort the matching document IDs (in relevance score order or value order)&lt;br /&gt;
##When complete, each forest returns a sorted iterator to the initiating server&lt;br /&gt;
#When each forest has returned an iterator&lt;br /&gt;
#It walks the sorted iterators from all the forests and combines the results in sorted &lt;br /&gt;
#It retrieves matching documents from its &#039;&#039;Expanded Tree Cache&#039;&#039; or from the forests when documents are not cached&lt;br /&gt;
##forests retrieve documents from their &#039;&#039;Compressed Tree Cache&#039;&#039; or from disk when documents are not cached&lt;br /&gt;
#It filters returned documents to remove false positive matches &lt;br /&gt;
#It optionally transforms documents &lt;br /&gt;
##It creates new documents by extracting matching elements, changing structure, changing file format, etc.&lt;br /&gt;
#It returns all matching (optionally transformed) documents to the requester&lt;br /&gt;
#It saves resulting document IDs when paging query results, so it can return subsequent pages of matching documents in subsequent requests&lt;br /&gt;
&lt;br /&gt;
The initiating server&#039;s process is CPU intensive, serialized, and blocks while waiting on forests. To prevent this from being a bottleneck to the cluster, you can dedicate nodes in the cluster to do nothing but evaluate queries. These are called e-nodes (evaluation nodes). These nodes don&#039;t hold data. If they held data, the &#039;&#039;serialized&#039;&#039; evaluation process would compete with the &#039;&#039;parallel&#039;&#039; index matching process.  Instead e-nodes are dedicated to validating, parsing, sorting, filtering, transforming, and paginating documents. They cache documents in the &#039;&#039;Expanded Tree Cache&#039;&#039; to minimize the number of documents they have to retrieve from data nodes (d-nodes). D-nodes only do parallel index processing and sorting. They cache documents in their &#039;&#039;Compressed Tree Cache&#039;&#039; to reduce disk IO. &lt;br /&gt;
&lt;br /&gt;
=== How do you optimize a MarkLogic cluster to run queries faster? ===&lt;br /&gt;
*E-nodes and d-nodes can be scaled independently to match the load. &lt;br /&gt;
*You can optimize an e-node by minimizing its &#039;&#039;Compressed Tree Cache&#039;&#039; and maximizing its &#039;&#039;Expanded Tree Cache&#039;&#039;. An e-node needs a big &#039;&#039;Expanded Tree Cache&#039;&#039; so it doesn&#039;t have to retrieve as many documents from d-nodes. An e-node doesn&#039;t need a &#039;&#039;Compressed Tree Cache&#039;&#039; because it doesn&#039;t have any data.&lt;br /&gt;
*You can optimize a d-node by doing the opposite of the e-node: maximize the &#039;&#039;Compressed Tree Cache&#039;&#039; and minimize the &#039;&#039;Expanded Tree Cache&#039;&#039;. You can also optimize d-nodes by making sure each d-node runs on similar hardware and that each forest has a similar number of documents. This is important because all forests process queries in parallel and the slowest forest holds up each query: e-nodes have to wait until the slowest forest finishes.&lt;br /&gt;
*You can optimize a query by making it unfiltered.&lt;br /&gt;
**This means it is completely resolved by the indexes. Because no filtering is required, the initiating server doesn&#039;t have to verify that documents match.&lt;br /&gt;
*You can optimize a query by eliminating false positives.  &lt;br /&gt;
**False positives occur when a query identifies a possible match for a document, but it cannot prove it is a match until the filtering process opens the document and verifies it. &lt;br /&gt;
**False positives happen because MarkLogic only partially indexes certain document items. MarkLogic cannot index everything because it would take too much time and space. For example, MarkLogic has a structure index. It indexes relationships between elements in a document.  MarkLogic cannot afford to index each element&#039;s path from itself to every other element. MarkLogic compromises on indexing only parent/child relationships. This is effective in eliminating most non-matching documents, but it can produce false positives.  The only way to know if a document is an &#039;&#039;exact&#039;&#039; match, MarkLogic must open the document and verify it.&lt;br /&gt;
**For example, suppose a query searches for the following path: &amp;lt;br&amp;gt;&amp;lt;code&amp;gt;books/poetry/poem&amp;lt;/code&amp;gt;&amp;lt;br&amp;gt; The structure index will match documents containing books/poetry and poetry/poem. The resulting documents are a probable match, but could contain false positives, such as &amp;lt;br&amp;gt;&amp;lt;code&amp;gt;books/poetry/fantasy/poetry/poem&amp;lt;/code&amp;gt;.&lt;br /&gt;
**You can eliminate false positive structures queries by giving elements unique names. They are  unique no matter where in they are in the structure and they are more self-descriptive.  Instead of naming an element &amp;quot;line&amp;quot; which can mean many things, you can use the precise name  &amp;quot;poemTextLine&amp;quot;. &lt;br /&gt;
*You can optimize a query by greatly limiting how many documents it matches. Design each query to return as few documents as possible. &lt;br /&gt;
**It is expensive to transmit documents. Matching documents have to travel from stands to forests to the initiating server, and to the requester. &lt;br /&gt;
**It is expensive to process documents on the initiating server and the requester. &lt;br /&gt;
**It takes processing time on d-nodes to compare lists of document IDs. The fewer the matching document IDs in one part of the query, the faster the entire query runs. &lt;br /&gt;
**The more matching document IDs, the more work MarkLogic has to do in a d-node to compare, union, intersect, and subract them from matching document IDs returned by other parts of the query. &lt;br /&gt;
**The more matching document IDs, the more sorting MarkLogic has to do in the stands, forests, and initiating server.&lt;br /&gt;
&lt;br /&gt;
=== How does a MarkLogic query compare to map/reduce? ===&lt;br /&gt;
A MarkLogic query or search is similar to map/reduce.  When you query or search for documents in a database, MarkLogic spreads the work across all the servers to be executed in parallel. This is like a &#039;&#039;map&#039;&#039; process because indexes filter out non-matching documents by combining term, range, and semantic indexes according to the query map. The results are then &#039;&#039;reduced&#039;&#039; at the forest level and again at the database level and again at the initiating server. This parallel division of responsibilities enables MarkLogic to scale.&lt;br /&gt;
&lt;br /&gt;
== Term, Range, and Semantic Indexes ==&lt;br /&gt;
MarkLogic indexes are not B-Tree indexes. MarkLogic uses &#039;&#039;&#039;term&#039;&#039;&#039;, &#039;&#039;&#039;range&#039;&#039;&#039;, and &#039;&#039;&#039;semantic&#039;&#039;&#039; indexes. &lt;br /&gt;
*&#039;&#039;&#039;A term index&#039;&#039;&#039; associates a term with every document that contains the term.  For example, in a word index, every word in the database is stored in the index. Associated with each word in the index is a list of each document ID that contains the term.  &lt;br /&gt;
*&#039;&#039;&#039;A range index&#039;&#039;&#039; is a double term index: it contains each term and all document IDs that contain that term, and it contains each document ID and all the terms that are in the document.&lt;br /&gt;
*&#039;&#039;&#039;A semantic index&#039;&#039;&#039; is similar to a range index but it is optimized to store triples (three pieces of data: subject, object, and predicate).&lt;br /&gt;
&lt;br /&gt;
Term indexes are fast. Give the index a term, and with one lookup, it returns &#039;&#039;all&#039;&#039; documents that contain the term. Term indexes are memory mapped files. They run in RAM unless you run out of RAM and then firmware in the CPU efficiently swaps them to and from disk. Thus, it is best to have enough RAM in a MarkLogic server to contain all indexes in memory.&lt;br /&gt;
&lt;br /&gt;
Unlike B-Tree indexes, term indexes are easily sharded within and between servers. MarkLogic takes advantage of this to run queries in parallel within and across servers. This is how MarkLogic can scale to billions of documents and still return queries and searches in milliseconds.&lt;br /&gt;
&lt;br /&gt;
When documents are inserted or updated, MarkLogic indexes them in RAM (as well as appends the changes to a journal on disk). When documents in RAM start to consume too much RAM, MarkLogic writes them to disk as a &amp;quot;stand&amp;quot; in a &amp;quot;forest&amp;quot; and starts creating a new &amp;quot;stand&amp;quot; in RAM.  &lt;br /&gt;
&lt;br /&gt;
When you query or search for documents, MarkLogic goes to the indexes in the stands (which are cached in RAM) and evaluates the query in parallel. Each stand index returns a list of document IDs (a list of numbers) that match the query. MarkLogic takes the document IDs returned by each stand and merges them into a final list of document IDs, which it uses to retrieve the documents from cache or disk. This works well because computers are very fast at sort merging lists of numbers.&lt;br /&gt;
&lt;br /&gt;
MarkLogic uses the same indexes for both queries and searches. This allows you to combine search and query expressions. The main difference between search and query is how documents are sorted: searches sort by relevance and queries sort by values. Another difference is that queries tend to use value indexes and searches tend to use word and phrase indexes. &lt;br /&gt;
&lt;br /&gt;
=== What specific indexes does MarkLogic have? ===&lt;br /&gt;
MarkLogic uses indexes to extract words, values, structures, and links out of documents. An index is an altered view of a document. It enables you to search and query for documents &amp;lt;br&amp;gt;&#039;&#039;&#039;as if they contained only:&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
*&#039;&#039;&#039;Words:&#039;&#039;&#039; a flat set of words without structure, such as &amp;lt;br&amp;gt;&amp;lt;code&amp;gt;[&amp;quot;Mary&amp;quot;, &amp;quot;had&amp;quot;, &amp;quot;a&amp;quot;, &amp;quot;little&amp;quot;, &amp;quot;lamb&amp;quot;]&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
*&#039;&#039;&#039;Phrases:&#039;&#039;&#039; a flat set of phrases without structure, such as &amp;lt;br&amp;gt;&amp;lt;code&amp;gt;[&amp;quot;Mary had&amp;quot;, &amp;quot;had a&amp;quot;, &amp;quot;a little&amp;quot;, &amp;quot;little lamb&amp;quot;]&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
*&#039;&#039;&#039;Elements:&#039;&#039;&#039; a flat set of elements without values, such as &amp;lt;br&amp;gt;&amp;lt;code&amp;gt;[&amp;quot;poem&amp;quot;, &amp;quot;text&amp;quot;, &amp;quot;line&amp;quot;]&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
*&#039;&#039;&#039;Element-values:&#039;&#039;&#039; a flat set of elements with string values, such as &amp;lt;br&amp;gt;&amp;lt;code&amp;gt;&amp;quot;line&amp;quot;: &amp;quot;Mary had a little lamb&amp;quot;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
*&#039;&#039;&#039;Element-words:&#039;&#039;&#039; a flat set of elements with words, such as &amp;lt;br&amp;gt;&amp;lt;code&amp;gt;&amp;quot;line&amp;quot;: [&amp;quot;Mary&amp;quot;, &amp;quot;had&amp;quot;, &amp;quot;a&amp;quot;, &amp;quot;little&amp;quot;, &amp;quot;lamb&amp;quot;]&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
*&#039;&#039;&#039;Element-phrases:&#039;&#039;&#039; a flat set of elements with phrases, such as &amp;lt;br&amp;gt;&amp;lt;code&amp;gt;&amp;quot;line&amp;quot;: [&amp;quot;Mary had&amp;quot;, &amp;quot;had a&amp;quot;, &amp;quot;a little&amp;quot;, &amp;quot;little lamb&amp;quot;]&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
*&#039;&#039;&#039;Element-value lexicon:&#039;&#039;&#039; a flat set of elements with typed values, such as &amp;lt;br&amp;gt;&amp;lt;code&amp;gt;&amp;quot;lineSequence&amp;quot;: 3&amp;lt;/code&amp;gt;&amp;lt;br&amp;gt; or a list, count, or co-occurrence of element values scoped to a database, set of documents, or one document.&lt;br /&gt;
&lt;br /&gt;
*&#039;&#039;&#039;XPath-structure-value lexicon:&#039;&#039;&#039; a flat set of hierarchical elements with typed values, such as &amp;lt;br&amp;gt;&amp;lt;code&amp;gt;poem.text.line.lineSequence: 3&amp;lt;/code&amp;gt;&amp;lt;br&amp;gt; or a list, count, or co-occurrence of hierarchical element values scoped to a database, set of documents, or one document.&lt;br /&gt;
&lt;br /&gt;
*&#039;&#039;&#039;XPath-structure:&#039;&#039;&#039;hierarchical structures without values, such as &amp;lt;br&amp;gt;&amp;lt;code&amp;gt;poem.text.line&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
*&#039;&#039;&#039;XPath-structure-words:&#039;&#039;&#039; hierarchical structures with words, such as &amp;lt;br&amp;gt;&amp;lt;code&amp;gt;poem.text.line: [&amp;quot;Mary&amp;quot;, &amp;quot;had&amp;quot;, &amp;quot;a&amp;quot;, &amp;quot;little&amp;quot;, &amp;quot;lamb&amp;quot;]&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
*&#039;&#039;&#039;XPath-structure-phrases:&#039;&#039;&#039; hierarchical structures with phrases, such as &amp;lt;br&amp;gt;&amp;lt;code&amp;gt;poem.text.line: [&amp;quot;Mary had&amp;quot;, &amp;quot;had a&amp;quot;, &amp;quot;a little&amp;quot;, &amp;quot;little lamb&amp;quot;]&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
*&#039;&#039;&#039;XPath-structure-values:&#039;&#039;&#039; hierarchical structures with values, such as &amp;lt;br&amp;gt;&amp;lt;code&amp;gt;poem.text.line: &amp;quot;Mary had a little lamb&amp;quot;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
*&#039;&#039;&#039;RDF document links&#039;&#039;&#039; to other documents, such as &amp;lt;br&amp;gt;&amp;lt;code&amp;gt;{&amp;quot;subject&amp;quot;: &amp;quot;http://example.org/documents/thisDoc&amp;quot;, &amp;lt;br&amp;gt;&amp;quot;predicate&amp;quot;: &amp;quot;http://example.org/predicates/relatesSomehowTo&amp;quot;, &amp;lt;br&amp;gt;&amp;quot;object&amp;quot;: &amp;quot;http://example.org/documents/thatDoc&amp;quot;}&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
*&#039;&#039;&#039;RDF abstract links&#039;&#039;&#039; to other abstract concepts, such as &amp;lt;br&amp;gt;&amp;lt;code&amp;gt;{&amp;quot;subject&amp;quot;: &amp;quot;http://example.org/documents/thisDoc&amp;quot;, &amp;lt;br&amp;gt;&amp;quot;predicate&amp;quot;: &amp;quot;http://example.org/predicates/relatesSomehowTo&amp;quot;, &amp;lt;br&amp;gt;&amp;quot;object&amp;quot;: &amp;quot;http://example.org/documents/someConceptWithNoDocumentAtTheURI&amp;quot;}&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
*&#039;&#039;&#039;RDF data links&#039;&#039;&#039; to data, such as &amp;lt;br&amp;gt;&amp;lt;code&amp;gt;{&amp;quot;subject&amp;quot;: &amp;quot;http://example.org/documents/thisDoc&amp;quot;, &amp;lt;br&amp;gt;&amp;quot;predicate&amp;quot;: &amp;quot;http://example.org/predicates/ageInYears&amp;quot;, &amp;lt;br&amp;gt;&amp;quot;object&amp;quot;: 12}&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
MarkLogic can combine any of these indexes in any way to find matching documents.  It can sort the result by relevance or by value. &lt;br /&gt;
&lt;br /&gt;
Search and query expressions are fully composable; i.e. they can be nested inside each other and combined using AND, OR, and NOT expressions.&lt;br /&gt;
&lt;br /&gt;
== Search Functions in MarkLogic ==&lt;br /&gt;
=== Executing a Search ===&lt;br /&gt;
*&#039;&#039;&#039;&amp;lt;code&amp;gt;[http://docs.marklogic.com/cts:search cts:search]&amp;lt;/code&amp;gt;&#039;&#039;&#039; is the most important function because it executes a search and returns matching nodes. &lt;br /&gt;
**&#039;&#039;&#039;You must include an XPath expression&#039;&#039;&#039; to define which nodes to &#039;&#039;search&#039;&#039; within and to &#039;&#039;return&#039;&#039;. &lt;br /&gt;
***The search returns &#039;&#039;nodes&#039;&#039;, which can be documents, elements, attributes, or text. Thus, a search doesn&#039;t have to return entire documents. Depending on the scope of your XPath statement, it may return entire documents, or one matching node from each document, or many matching nodes from each document.  &lt;br /&gt;
**&#039;&#039;&#039;You must include a cts query expression&#039;&#039;&#039; to filter the contents of &#039;&#039;nodes&#039;&#039; selected by the XPath expression. This allows you to search for specific content within specific nodes and return only those nodes that contain that content. &lt;br /&gt;
***MarkLogic limits search results to words, phrases, values, and structures in the query that occur within the nodes specified by the XPath expression. &lt;br /&gt;
***If you want to return entire documents and search within specific elements and attributes, then the XPath expression should specify the root element and the query should use the element and  element-attribute queries to limit where the search occurs.&lt;br /&gt;
***If you want to return all the nodes selected by the XPath expression, you can use the empty query expression: &amp;lt;code&amp;gt;cts:and-query(())&amp;lt;/code&amp;gt;.&lt;br /&gt;
**You may limit the search to specific forests. You may set options like unfiltered, faceted, unchecked, quality weight, relevance scoring method, and relevance trace.&lt;br /&gt;
**Use Cases:&lt;br /&gt;
***A search can return entire documents whose contents match the XPath and query expressions.&lt;br /&gt;
***A search can extract and return titles from documents as long as the contents of the titles match the XPath and query expressions.&lt;br /&gt;
***A search can extract and return all the paragraphs from documents as long as the contents of the paragraphs match the XPath and query expressions.&lt;br /&gt;
**Notes:&lt;br /&gt;
***There is no functional difference between searching entire documents and elements because an element has the same structure as document.  Both may contain complex nested elements or both may simply contain a value. In both cases, MarkLogic retrieves entire documents. In the case of elements, it extracts the requested elements from each retrieved document.&lt;br /&gt;
***Searching attributes, text nodes, and childless elements is similar to searching documents and elements with children — except the cts query cannot look for nested structures.&lt;br /&gt;
&lt;br /&gt;
*&#039;&#039;&#039;&amp;lt;code&amp;gt;[http://docs.marklogic.com/cts:contains cts:contains]&amp;lt;/code&amp;gt;&#039;&#039;&#039; is the second most important function because it returns true when a cts query finds at least one matching node in the nodes returned by an XPath expression (or a sequence of values). In other words, it returns true when at least one of the specified nodes &#039;&#039;&#039;contains&#039;&#039;&#039; the precise combination of words, phrases, values, structures, and/or triples in a cts query. &lt;br /&gt;
**NOTE: in the second example for &amp;lt;code&amp;gt;[http://docs.marklogic.com/cts:not-query cts:not-query]&amp;lt;/code&amp;gt;, it says cts:contains forces the constraint to happen in the filtering stage of the query. Is this always true for cts:contains, or is it only true in the example?&lt;br /&gt;
&lt;br /&gt;
=== Constructing a Query ===&lt;br /&gt;
You compose a query using cts query constructor functions. You then execute the query by passing it into &amp;lt;code&amp;gt;cts:search, cts:contains, search:search&amp;lt;/code&amp;gt;, and lexicon functions. MarkLogic has 30+ query constructors. They all end in &#039;&#039;&#039;&amp;quot;-query&amp;quot;&#039;&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
==== Composite Query Constructors ====&lt;br /&gt;
The composite query constructors build up new queries from other queries, and queries can be nested within queries.&lt;br /&gt;
&lt;br /&gt;
*&#039;&#039;&#039;&amp;lt;code&amp;gt;[http://docs.marklogic.com/cts:and-query cts:and-query]&amp;lt;/code&amp;gt;&#039;&#039;&#039; returns a query that intersects two or more sub-queries. &lt;br /&gt;
**You may optionally specify an &amp;quot;ordered&amp;quot; option that requires document contents to match sub-queries in the order they are listed; for example if the sub-queries are &amp;quot;To be&amp;quot; and &amp;quot;or not to be&amp;quot;, then the query will match documents that have the phrase &amp;quot;To be&amp;quot; &#039;&#039;before&#039;&#039; &amp;quot;or not to be&amp;quot;. The default is &amp;quot;unordered&amp;quot;, which allows each sub-query to match the content in any order that it occurs in the document.  &lt;br /&gt;
**If you pass in the empty sequence, such as &amp;lt;code&amp;gt;cts:and-query(())&amp;lt;/code&amp;gt;, then it will match every document in the database.&lt;br /&gt;
&lt;br /&gt;
*&#039;&#039;&#039;&amp;lt;code&amp;gt;[http://docs.marklogic.com/cts:or-query cts:or-query]&amp;lt;/code&amp;gt;&#039;&#039;&#039; returns a query that unions two or more sub-queries.&lt;br /&gt;
&lt;br /&gt;
*&#039;&#039;&#039;&amp;lt;code&amp;gt;[http://docs.marklogic.com/cts:not-query cts:not-query]&amp;lt;/code&amp;gt;&#039;&#039;&#039; returns a query that subtracts one or more sub-queries.&lt;br /&gt;
**It works by taking the list of documents in the database and subtracting documents returned from its sub-queries. It returns all remaining documents. It does not filter documents returned from its sub-queries because filtering happens after all index resolution has completed, and &amp;lt;code&amp;gt;cts:not-query&amp;lt;/code) executes during index resolution. &lt;br /&gt;
**&#039;&#039;&#039;Warning:&#039;&#039;&#039; cts:not-query can be inaccurate. It can be missing documents when any of its sub-queries requires filtering to be accurate. It only produces accurate results when all its sub-queries are resolvable completely from indexes with no filtering required. &lt;br /&gt;
***When sub-queries require filtering, they may return false-positive matches. A false-positive match occurs when the indexes cannot determine for sure if a document matches so MarkLogic includes it just in case. As the last step in a query, MarkLogic opens all the potentially matching documents returned by the indexes and filters out any false-positive matches. &lt;br /&gt;
***When &amp;lt;code&amp;gt;cts:not-query&amp;lt;/code&amp;gt; subtracts its sub-queries from the documents in the database, it also subtracts false-positive matches because it runs during index resolution and before filtering occurs. If there are false-positive matches, then &amp;lt;code&amp;gt;cts:not-query&amp;lt;/code&amp;gt; won&#039;t include them. If the sub-queries return inaccurate false-positive matches, then they get subtracted out of the results, which creates inaccurate results. When the sub-queries return accurate results (with no false-positives), then the results of &amp;lt;code&amp;gt;cts:not-query&amp;lt;/code&amp;gt; are accurate. &lt;br /&gt;
&lt;br /&gt;
*&#039;&#039;&#039;&amp;lt;code&amp;gt;[http://docs.marklogic.com/cts:and-not-query cts:and-not-query]&amp;lt;/code&amp;gt;&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
*&#039;&#039;&#039;&amp;lt;code&amp;gt;[http://docs.marklogic.com/cts:element-query cts:element-query]&amp;lt;/code&amp;gt;&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
*&#039;&#039;&#039;&amp;lt;code&amp;gt;[http://docs.marklogic.com/cts:document-fragment-query cts:document-fragment-query]&amp;lt;/code&amp;gt;&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
*&#039;&#039;&#039;&amp;lt;code&amp;gt;[http://docs.marklogic.com/cts:locks-query cts:locks-query]&amp;lt;/code&amp;gt;&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
*&#039;&#039;&#039;&amp;lt;code&amp;gt;[http://docs.marklogic.com/cts:properties-query cts:properties-query]&amp;lt;/code&amp;gt;&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
*&#039;&#039;&#039;&amp;lt;code&amp;gt;[http://docs.marklogic.com/cts:near-query cts:near-query]&amp;lt;/code&amp;gt;&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Training Resources for MarkLogic Search ==&lt;br /&gt;
* [http://developer.marklogic.com/blog/grokking-the-cts-api &amp;quot;Grokking the cts API&amp;quot;] is a great overview of MarkLogic&#039;s search and query capabilities.&lt;br /&gt;
&lt;br /&gt;
[[Category: MarkLogic]]&lt;/div&gt;</summary>
		<author><name>Bowersmt</name></author>
	</entry>
	<entry>
		<id>https://tech.churchofjesuschrist.org/wiki/index.php?title=MarkLogic_Query_and_Search&amp;diff=70577</id>
		<title>MarkLogic Query and Search</title>
		<link rel="alternate" type="text/html" href="https://tech.churchofjesuschrist.org/wiki/index.php?title=MarkLogic_Query_and_Search&amp;diff=70577"/>
		<updated>2014-11-19T04:49:10Z</updated>

		<summary type="html">&lt;p&gt;Bowersmt: Clarified how cts:search works&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[[MarkLogic|« Back to MarkLogic]]&lt;br /&gt;
&lt;br /&gt;
== Searching and Querying MarkLogic ==&lt;br /&gt;
Indexes are central to everything you do in MarkLogic.  They are central to how MarkLogic stores data, scales massively, and processes data quickly. They are central to how you develop because you have to use MarkLogic&#039;s indexes to query and search documents. You have to understand how MarkLogic&#039;s indexes work to be able to create fast queries. And you have to know how to model document structure to work best with indexes.&lt;br /&gt;
&lt;br /&gt;
=== How does MarkLogic compare to a relational database? ===&lt;br /&gt;
A document in MarkLogic is very much like a row in a relational database, and a document type ties documents together like a table ties rows together. MarkLogic collections group documents together in any way you want. Collections are like views in a relational database, which group together a filtered set of rows from one or more tables, but collections do not join and merge document content and views cannot arbitrarily include any row from any table. A document in MarkLogic can have a flat structure like a relational table, or it can contain complex nestings of data.  Each nesting of data in a document represents another table in a relational database. For example, a single document in MarkLogic may represent many relational tables, and how they are nested represents their one-to-one, many-to-one, and many-to-many relationships.  &lt;br /&gt;
&lt;br /&gt;
Both MarkLogic and relational databases use indexes to resolve queries without having to scan through all documents or rows. MarkLogic indexes are designed to find any word, phrase, value, element, or element structure -- no matter where it occurs in document structure, no matter how many times it occurs within a document, and no matter what type of document contains it. For example, you can search for and return a &amp;lt;title&amp;gt; element and MarkLogic will return the contents of all &amp;lt;title&amp;gt; elements it finds — even if &amp;lt;title&amp;gt; elements are in different types of documents. This is similar to doing a union query across multiple tables in relational databases. &lt;br /&gt;
&lt;br /&gt;
MarkLogic indexes also let you search for words, phrases, values, elements, or element structures in very specific locations, such as in only certain types of documents or within certain document structures, or in specific collections or folders. For example, you can search for and return all &amp;lt;title&amp;gt; elements that are found in the header section of poetry documents in the Shakespeare and Tennyson collections. &lt;br /&gt;
&lt;br /&gt;
MarkLogic is not designed for joining documents like a relational database.  A relational join searches for matching values across two or more tables and then merges matching rows into a single row. This can be done in MarkLogic, but you have to write advanced code to iterate through query results to match values across different document types, and merge matching documents into a single document. Also since MarkLogic documents are often nested structures, you can&#039;t simply merge them, you have to copy nested content from one document into a specific nested location in another.&lt;br /&gt;
&lt;br /&gt;
Unlike relational databases, MarkLogic can&#039;t do full table scans; queries must use indexes. In contrast, relational databases often use a full table scan to retrieve every row in a table. A rule of thumb in relational databases is that it is faster to directly read in &#039;&#039;all&#039;&#039; the rows when a query accesses more than roughly 25% of the rows. This is because relational databases use variations of the B-Tree index, which requires 3-4 random IOs to find one row and 1 IO to retrieve the row: this is 4-5 total IOs per row.  B-Tree indexes work best for single row lookups, but they become increasingly costly the more rows they retrieve. If an index has to lookup 25% of its rows with 4 IOs per row, the database will do the same amount of IO if it reads in all of the rows (1 IO per row). Since sequential IO on disks is faster than random IO, relational databases prefer full table scans when accessing more than about 25% of rows in a table. On analytical data warehouses, full table scans are always preferred.  &lt;br /&gt;
&lt;br /&gt;
In addition, a relational database [https://docs.oracle.com/database/121/TGSQL/tgsql_optop.htm#TGSQL234 often directly scans through index data] rather than stepping through its B-Tree structure. Databases use a variety of index scans: full scans, range scans, skip scans, join scans, etc. This is index and table records are stored sequentially on disk. This often makes it faster to take advantage of the speed of sequential disk IO and directly load all index or table rows into RAM and process them in RAM; as opposed to walking a b-tree structure and doing multiple slow random IOs to retrieve each record. For the same reason, row and index scans work well in columnar NoSQL databases.&lt;br /&gt;
&lt;br /&gt;
=== Why do MarkLogic queries have to use Indexes? ===&lt;br /&gt;
To maximize parallelism and to spread processing throughout a cluster, MarkLogic spreads documents across the cluster. MarkLogic automatically creates multiple shards per server and spreads them across all the servers in the cluster. Documents are placed in a shard in the order they are created or modified; thus, documents of all types may be randomly intermixed in a shard. Since a shard is not organized by document type, doing a sequential scan to resolve a query would require retrieving and processing all documents in the database. Full scans are not practical in MarkLogic. All queries and searches need to use indexes. For this reason, MarkLogic automatically indexes almost everything. You can also create additional specialized indexes.  MarkLogic indexes are not B-Tree indexes; they are designed to be sharded and queried in parallel across stands, forests, and a database cluster that spans many servers.&lt;br /&gt;
&lt;br /&gt;
=== How does MarkLogic scale horizontally? ===&lt;br /&gt;
Documents in MarkLogic belong to a database. Within a database are one or more servers.  Each server may contain zero or more &amp;quot;forests&amp;quot;. Within each forest are one or more &amp;quot;stands&amp;quot;. Within each stand are one or more &amp;quot;trees&amp;quot;. A document is hierarchical so it is called a &amp;quot;tree&amp;quot;.  (MarkLogic uses the terms &amp;quot;stand&amp;quot; and &amp;quot;forest&amp;quot; instead of &amp;quot;shard&amp;quot;, but they have the same meaning.) &lt;br /&gt;
&lt;br /&gt;
A client contacts one of the servers in a MarkLogic cluster and initiates a query or search. Because MarkLogic communicates through REST web services, a load balancer can spread requests across the servers in a MarkLogic cluster.  The initiating server does the following&lt;br /&gt;
#It validates the query request from the client&lt;br /&gt;
#It parses and optimizes the query &lt;br /&gt;
#It sends the query to all servers that have forests in the database&lt;br /&gt;
##Each server sends it to its forests &lt;br /&gt;
##Each forest sends it to each stand &lt;br /&gt;
##Each stand uses its indexes to find matching documents&lt;br /&gt;
###All stands and forests query the indexes in parallel&lt;br /&gt;
##Forests combine the matching document IDs from all their stands&lt;br /&gt;
##Forests sort the matching document IDs (in relevance score order or value order)&lt;br /&gt;
##When complete, each forest returns a sorted iterator to the initiating server&lt;br /&gt;
#When each forest has returned an iterator&lt;br /&gt;
#It walks the sorted iterators from all the forests and combines the results in sorted &lt;br /&gt;
#It retrieves matching documents from its &#039;&#039;Expanded Tree Cache&#039;&#039; or from the forests when documents are not cached&lt;br /&gt;
##forests retrieve documents from their &#039;&#039;Compressed Tree Cache&#039;&#039; or from disk when documents are not cached&lt;br /&gt;
#It filters returned documents to remove false positive matches &lt;br /&gt;
#It optionally transforms documents &lt;br /&gt;
##It creates new documents by extracting matching elements, changing structure, changing file format, etc.&lt;br /&gt;
#It returns all matching (optionally transformed) documents to the requester&lt;br /&gt;
#It saves resulting document IDs when paging query results, so it can return subsequent pages of matching documents in subsequent requests&lt;br /&gt;
&lt;br /&gt;
The initiating server&#039;s process is CPU intensive, serialized, and blocks while waiting on forests. To prevent this from being a bottleneck to the cluster, you can dedicate nodes in the cluster to do nothing but evaluate queries. These are called e-nodes (evaluation nodes). These nodes don&#039;t hold data. If they held data, the &#039;&#039;serialized&#039;&#039; evaluation process would compete with the &#039;&#039;parallel&#039;&#039; index matching process.  Instead e-nodes are dedicated to validating, parsing, sorting, filtering, transforming, and paginating documents. They cache documents in the &#039;&#039;Expanded Tree Cache&#039;&#039; to minimize the number of documents they have to retrieve from data nodes (d-nodes). D-nodes only do parallel index processing and sorting. They cache documents in their &#039;&#039;Compressed Tree Cache&#039;&#039; to reduce disk IO. &lt;br /&gt;
&lt;br /&gt;
=== How do you optimize a MarkLogic cluster to run queries faster? ===&lt;br /&gt;
*E-nodes and d-nodes can be scaled independently to match the load. &lt;br /&gt;
*You can optimize an e-node by minimizing its &#039;&#039;Compressed Tree Cache&#039;&#039; and maximizing its &#039;&#039;Expanded Tree Cache&#039;&#039;. An e-node needs a big &#039;&#039;Expanded Tree Cache&#039;&#039; so it doesn&#039;t have to retrieve as many documents from d-nodes. An e-node doesn&#039;t need a &#039;&#039;Compressed Tree Cache&#039;&#039; because it doesn&#039;t have any data.&lt;br /&gt;
*You can optimize a d-node by doing the opposite of the e-node: maximize the &#039;&#039;Compressed Tree Cache&#039;&#039; and minimize the &#039;&#039;Expanded Tree Cache&#039;&#039;. You can also optimize d-nodes by making sure each d-node runs on similar hardware and that each forest has a similar number of documents. This is important because all forests process queries in parallel and the slowest forest holds up each query: e-nodes have to wait until the slowest forest finishes.&lt;br /&gt;
*You can optimize a query by making it unfiltered.&lt;br /&gt;
**This means it is completely resolved by the indexes. Because no filtering is required, the initiating server doesn&#039;t have to verify that documents match.&lt;br /&gt;
*You can optimize a query by eliminating false positives.  &lt;br /&gt;
**False positives occur when a query identifies a possible match for a document, but it cannot prove it is a match until the filtering process opens the document and verifies it. &lt;br /&gt;
**False positives happen because MarkLogic only partially indexes certain document items. MarkLogic cannot index everything because it would take too much time and space. For example, MarkLogic has a structure index. It indexes relationships between elements in a document.  MarkLogic cannot afford to index each element&#039;s path from itself to every other element. MarkLogic compromises on indexing only parent/child relationships. This is effective in eliminating most non-matching documents, but it can produce false positives.  The only way to know if a document is an &#039;&#039;exact&#039;&#039; match, MarkLogic must open the document and verify it.&lt;br /&gt;
**For example, suppose a query searches for the following path: &amp;lt;br&amp;gt;&amp;lt;code&amp;gt;books/poetry/poem&amp;lt;/code&amp;gt;&amp;lt;br&amp;gt; The structure index will match documents containing books/poetry and poetry/poem. The resulting documents are a probable match, but could contain false positives, such as &amp;lt;br&amp;gt;&amp;lt;code&amp;gt;books/poetry/fantasy/poetry/poem&amp;lt;/code&amp;gt;.&lt;br /&gt;
**You can eliminate false positive structures queries by giving elements unique names. They are  unique no matter where in they are in the structure and they are more self-descriptive.  Instead of naming an element &amp;quot;line&amp;quot; which can mean many things, you can use the precise name  &amp;quot;poemTextLine&amp;quot;. &lt;br /&gt;
*You can optimize a query by greatly limiting how many documents it matches. Design each query to return as few documents as possible. &lt;br /&gt;
**It is expensive to transmit documents. Matching documents have to travel from stands to forests to the initiating server, and to the requester. &lt;br /&gt;
**It is expensive to process documents on the initiating server and the requester. &lt;br /&gt;
**It takes processing time on d-nodes to compare lists of document IDs. The fewer the matching document IDs in one part of the query, the faster the entire query runs. &lt;br /&gt;
**The more matching document IDs, the more work MarkLogic has to do in a d-node to compare, union, intersect, and subract them from matching document IDs returned by other parts of the query. &lt;br /&gt;
**The more matching document IDs, the more sorting MarkLogic has to do in the stands, forests, and initiating server.&lt;br /&gt;
&lt;br /&gt;
=== How does a MarkLogic query compare to map/reduce? ===&lt;br /&gt;
A MarkLogic query or search is similar to map/reduce.  When you query or search for documents in a database, MarkLogic spreads the work across all the servers to be executed in parallel. This is like a &#039;&#039;map&#039;&#039; process because indexes filter out non-matching documents by combining term, range, and semantic indexes according to the query map. The results are then &#039;&#039;reduced&#039;&#039; at the forest level and again at the database level and again at the initiating server. This parallel division of responsibilities enables MarkLogic to scale.&lt;br /&gt;
&lt;br /&gt;
== Term, Range, and Semantic Indexes ==&lt;br /&gt;
MarkLogic indexes are not B-Tree indexes. MarkLogic uses &#039;&#039;&#039;term&#039;&#039;&#039;, &#039;&#039;&#039;range&#039;&#039;&#039;, and &#039;&#039;&#039;semantic&#039;&#039;&#039; indexes. &lt;br /&gt;
*&#039;&#039;&#039;A term index&#039;&#039;&#039; associates a term with every document that contains the term.  For example, in a word index, every word in the database is stored in the index. Associated with each word in the index is a list of each document ID that contains the term.  &lt;br /&gt;
*&#039;&#039;&#039;A range index&#039;&#039;&#039; is a double term index: it contains each term and all document IDs that contain that term, and it contains each document ID and all the terms that are in the document.&lt;br /&gt;
*&#039;&#039;&#039;A semantic index&#039;&#039;&#039; is similar to a range index but it is optimized to store triples (three pieces of data: subject, object, and predicate).&lt;br /&gt;
&lt;br /&gt;
Term indexes are fast. Give the index a term, and with one lookup, it returns &#039;&#039;all&#039;&#039; documents that contain the term. Term indexes are memory mapped files. They run in RAM unless you run out of RAM and then firmware in the CPU efficiently swaps them to and from disk. Thus, it is best to have enough RAM in a MarkLogic server to contain all indexes in memory.&lt;br /&gt;
&lt;br /&gt;
Unlike B-Tree indexes, term indexes are easily sharded within and between servers. MarkLogic takes advantage of this to run queries in parallel within and across servers. This is how MarkLogic can scale to billions of documents and still return queries and searches in milliseconds.&lt;br /&gt;
&lt;br /&gt;
When documents are inserted or updated, MarkLogic indexes them in RAM (as well as appends the changes to a journal on disk). When documents in RAM start to consume too much RAM, MarkLogic writes them to disk as a &amp;quot;stand&amp;quot; in a &amp;quot;forest&amp;quot; and starts creating a new &amp;quot;stand&amp;quot; in RAM.  &lt;br /&gt;
&lt;br /&gt;
When you query or search for documents, MarkLogic goes to the indexes in the stands (which are cached in RAM) and evaluates the query in parallel. Each stand index returns a list of document IDs (a list of numbers) that match the query. MarkLogic takes the document IDs returned by each stand and merges them into a final list of document IDs, which it uses to retrieve the documents from cache or disk. This works well because computers are very fast at sort merging lists of numbers.&lt;br /&gt;
&lt;br /&gt;
MarkLogic uses the same indexes for both queries and searches. This allows you to combine search and query expressions. The main difference between search and query is how documents are sorted: searches sort by relevance and queries sort by values. Another difference is that queries tend to use value indexes and searches tend to use word and phrase indexes. &lt;br /&gt;
&lt;br /&gt;
=== What specific indexes does MarkLogic have? ===&lt;br /&gt;
MarkLogic uses indexes to extract words, values, structures, and links out of documents. An index is an altered view of a document. It enables you to search and query for documents &amp;lt;br&amp;gt;&#039;&#039;&#039;as if they contained only:&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
*&#039;&#039;&#039;Words:&#039;&#039;&#039; a flat set of words without structure, such as &amp;lt;br&amp;gt;&amp;lt;code&amp;gt;[&amp;quot;Mary&amp;quot;, &amp;quot;had&amp;quot;, &amp;quot;a&amp;quot;, &amp;quot;little&amp;quot;, &amp;quot;lamb&amp;quot;]&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
*&#039;&#039;&#039;Phrases:&#039;&#039;&#039; a flat set of phrases without structure, such as &amp;lt;br&amp;gt;&amp;lt;code&amp;gt;[&amp;quot;Mary had&amp;quot;, &amp;quot;had a&amp;quot;, &amp;quot;a little&amp;quot;, &amp;quot;little lamb&amp;quot;]&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
*&#039;&#039;&#039;Elements:&#039;&#039;&#039; a flat set of elements without values, such as &amp;lt;br&amp;gt;&amp;lt;code&amp;gt;[&amp;quot;poem&amp;quot;, &amp;quot;text&amp;quot;, &amp;quot;line&amp;quot;]&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
*&#039;&#039;&#039;Element-values:&#039;&#039;&#039; a flat set of elements with string values, such as &amp;lt;br&amp;gt;&amp;lt;code&amp;gt;&amp;quot;line&amp;quot;: &amp;quot;Mary had a little lamb&amp;quot;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
*&#039;&#039;&#039;Element-words:&#039;&#039;&#039; a flat set of elements with words, such as &amp;lt;br&amp;gt;&amp;lt;code&amp;gt;&amp;quot;line&amp;quot;: [&amp;quot;Mary&amp;quot;, &amp;quot;had&amp;quot;, &amp;quot;a&amp;quot;, &amp;quot;little&amp;quot;, &amp;quot;lamb&amp;quot;]&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
*&#039;&#039;&#039;Element-phrases:&#039;&#039;&#039; a flat set of elements with phrases, such as &amp;lt;br&amp;gt;&amp;lt;code&amp;gt;&amp;quot;line&amp;quot;: [&amp;quot;Mary had&amp;quot;, &amp;quot;had a&amp;quot;, &amp;quot;a little&amp;quot;, &amp;quot;little lamb&amp;quot;]&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
*&#039;&#039;&#039;Element-value lexicon:&#039;&#039;&#039; a flat set of elements with typed values, such as &amp;lt;br&amp;gt;&amp;lt;code&amp;gt;&amp;quot;lineSequence&amp;quot;: 3&amp;lt;/code&amp;gt;&amp;lt;br&amp;gt; or a list, count, or co-occurrence of element values scoped to a database, set of documents, or one document.&lt;br /&gt;
&lt;br /&gt;
*&#039;&#039;&#039;XPath-structure-value lexicon:&#039;&#039;&#039; a flat set of hierarchical elements with typed values, such as &amp;lt;br&amp;gt;&amp;lt;code&amp;gt;poem.text.line.lineSequence: 3&amp;lt;/code&amp;gt;&amp;lt;br&amp;gt; or a list, count, or co-occurrence of hierarchical element values scoped to a database, set of documents, or one document.&lt;br /&gt;
&lt;br /&gt;
*&#039;&#039;&#039;XPath-structure:&#039;&#039;&#039;hierarchical structures without values, such as &amp;lt;br&amp;gt;&amp;lt;code&amp;gt;poem.text.line&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
*&#039;&#039;&#039;XPath-structure-words:&#039;&#039;&#039; hierarchical structures with words, such as &amp;lt;br&amp;gt;&amp;lt;code&amp;gt;poem.text.line: [&amp;quot;Mary&amp;quot;, &amp;quot;had&amp;quot;, &amp;quot;a&amp;quot;, &amp;quot;little&amp;quot;, &amp;quot;lamb&amp;quot;]&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
*&#039;&#039;&#039;XPath-structure-phrases:&#039;&#039;&#039; hierarchical structures with phrases, such as &amp;lt;br&amp;gt;&amp;lt;code&amp;gt;poem.text.line: [&amp;quot;Mary had&amp;quot;, &amp;quot;had a&amp;quot;, &amp;quot;a little&amp;quot;, &amp;quot;little lamb&amp;quot;]&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
*&#039;&#039;&#039;XPath-structure-values:&#039;&#039;&#039; hierarchical structures with values, such as &amp;lt;br&amp;gt;&amp;lt;code&amp;gt;poem.text.line: &amp;quot;Mary had a little lamb&amp;quot;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
*&#039;&#039;&#039;RDF document links&#039;&#039;&#039; to other documents, such as &amp;lt;br&amp;gt;&amp;lt;code&amp;gt;{&amp;quot;subject&amp;quot;: &amp;quot;http://example.org/documents/thisDoc&amp;quot;, &amp;lt;br&amp;gt;&amp;quot;predicate&amp;quot;: &amp;quot;http://example.org/predicates/relatesSomehowTo&amp;quot;, &amp;lt;br&amp;gt;&amp;quot;object&amp;quot;: &amp;quot;http://example.org/documents/thatDoc&amp;quot;}&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
*&#039;&#039;&#039;RDF abstract links&#039;&#039;&#039; to other abstract concepts, such as &amp;lt;br&amp;gt;&amp;lt;code&amp;gt;{&amp;quot;subject&amp;quot;: &amp;quot;http://example.org/documents/thisDoc&amp;quot;, &amp;lt;br&amp;gt;&amp;quot;predicate&amp;quot;: &amp;quot;http://example.org/predicates/relatesSomehowTo&amp;quot;, &amp;lt;br&amp;gt;&amp;quot;object&amp;quot;: &amp;quot;http://example.org/documents/someConceptWithNoDocumentAtTheURI&amp;quot;}&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
*&#039;&#039;&#039;RDF data links&#039;&#039;&#039; to data, such as &amp;lt;br&amp;gt;&amp;lt;code&amp;gt;{&amp;quot;subject&amp;quot;: &amp;quot;http://example.org/documents/thisDoc&amp;quot;, &amp;lt;br&amp;gt;&amp;quot;predicate&amp;quot;: &amp;quot;http://example.org/predicates/ageInYears&amp;quot;, &amp;lt;br&amp;gt;&amp;quot;object&amp;quot;: 12}&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
MarkLogic can combine any of these indexes in any way to find matching documents.  It can sort the result by relevance or by value. &lt;br /&gt;
&lt;br /&gt;
Search and query expressions are fully composable; i.e. they can be nested inside each other and combined using AND, OR, and NOT expressions.&lt;br /&gt;
&lt;br /&gt;
== Search Functions in MarkLogic ==&lt;br /&gt;
=== Executing a Search ===&lt;br /&gt;
*&#039;&#039;&#039;&amp;lt;code&amp;gt;[http://docs.marklogic.com/cts:search cts:search]&amp;lt;/code&amp;gt;&#039;&#039;&#039; is the most important function because it executes a search and returns matching nodes. &lt;br /&gt;
**&#039;&#039;&#039;You must include an XPath expression&#039;&#039;&#039; to define which nodes to &#039;&#039;search&#039;&#039; within and to &#039;&#039;return&#039;&#039;. &lt;br /&gt;
***The search returns &#039;&#039;nodes&#039;&#039;, which can be documents, elements, attributes, or text. Thus, a search doesn&#039;t have to return entire documents. Depending on the scope of your XPath statement, it may return entire documents, or one matching node from each document, or many matching nodes from each document.  &lt;br /&gt;
**&#039;&#039;&#039;You must include a cts query expression&#039;&#039;&#039; to filter the contents of &#039;&#039;nodes&#039;&#039; selected by the XPath expression. This allows you to search for specific content within specific nodes and return only those nodes that contain that content. &lt;br /&gt;
***MarkLogic limits search results to words, phrases, values, and structures in the query that occur within the nodes specified by the XPath expression. &lt;br /&gt;
***If you want to return entire documents and search within specific elements and attributes, then the XPath expression should specify the root element and the query should use the element and  element-attribute queries to limit where the search occurs.&lt;br /&gt;
***If you want to return all the nodes selected by the XPath expression, you can use the empty query expression: &amp;lt;code&amp;gt;cts:and-query(())&amp;lt;/code&amp;gt;.&lt;br /&gt;
**You may limit the search to specific forests. You may set options like unfiltered, faceted, unchecked, quality weight, relevance scoring method, and relevance trace.&lt;br /&gt;
**Use Cases:&lt;br /&gt;
***A search can return entire documents whose contents match the XPath and query expressions.&lt;br /&gt;
***A search can extract and return titles from documents as long as the contents of the titles match the XPath and query expressions.&lt;br /&gt;
***A search can extract and return all the paragraphs from documents as long as the contents of the paragraphs match the XPath and query expressions.&lt;br /&gt;
**Notes:&lt;br /&gt;
***There is no functional difference between searching entire documents and elements because an element has the same structure as document.  Both may contain complex nested elements or both may simply contain a value. In both cases, MarkLogic retrieves entire documents. In the case of elements, it extracts the requested elements from each retrieved document.&lt;br /&gt;
***Searching attributes, text nodes, and childless elements is similar to searching documents and elements with children — except the cts query cannot look for nested structures.&lt;br /&gt;
&lt;br /&gt;
*&#039;&#039;&#039;&amp;lt;code&amp;gt;[http://docs.marklogic.com/cts:contains cts:contains]&amp;lt;/code&amp;gt;&#039;&#039;&#039; is the second most important function because it returns true when a cts query finds at least one matching node in the nodes returned by an XPath expression (or a sequence of values). In other words, it returns true when at least one of the specified nodes &#039;&#039;&#039;contains&#039;&#039;&#039; the precise combination of words, phrases, values, structures, and/or triples in a cts query.&lt;br /&gt;
&lt;br /&gt;
=== Constructing a Query ===&lt;br /&gt;
You compose a query using cts query constructor functions. You then execute the query by passing it into &amp;lt;code&amp;gt;cts:search, cts:contains, search:search&amp;lt;/code&amp;gt;, and lexicon functions. MarkLogic has 30+ query constructors. They all end in &#039;&#039;&#039;&amp;quot;-query&amp;quot;&#039;&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
==== Composite Query Constructors ====&lt;br /&gt;
The composite query constructors build up new queries from other queries, and queries can be nested within queries.&lt;br /&gt;
&lt;br /&gt;
*&#039;&#039;&#039;&amp;lt;code&amp;gt;[http://docs.marklogic.com/cts:and-query cts:and-query]&amp;lt;/code&amp;gt;&#039;&#039;&#039; returns a query that intersects two or more sub-queries. &lt;br /&gt;
**You may optionally specify an &amp;quot;ordered&amp;quot; option that requires document contents to match sub-queries in the order they are listed; for example if the sub-queries are &amp;quot;To be&amp;quot; and &amp;quot;or not to be&amp;quot;, then the query will match documents that have the phrase &amp;quot;To be&amp;quot; &#039;&#039;before&#039;&#039; &amp;quot;or not to be&amp;quot;. The default is &amp;quot;unordered&amp;quot;, which allows each sub-query to match the content in any order that it occurs in the document.  &lt;br /&gt;
**If you pass in the empty sequence, such as &amp;lt;code&amp;gt;cts:and-query(())&amp;lt;/code&amp;gt;, then it will match every document in the database.&lt;br /&gt;
&lt;br /&gt;
*&#039;&#039;&#039;&amp;lt;code&amp;gt;[http://docs.marklogic.com/cts:or-query cts:or-query]&amp;lt;/code&amp;gt;&#039;&#039;&#039; returns a query that unions two or more sub-queries.&lt;br /&gt;
&lt;br /&gt;
*&#039;&#039;&#039;&amp;lt;code&amp;gt;[http://docs.marklogic.com/cts:not-query cts:not-query]&amp;lt;/code&amp;gt;&#039;&#039;&#039; returns a query that subtracts one or more sub-queries.&lt;br /&gt;
&lt;br /&gt;
*&#039;&#039;&#039;&amp;lt;code&amp;gt;[http://docs.marklogic.com/cts:and-not-query cts:and-not-query]&amp;lt;/code&amp;gt;&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
*&#039;&#039;&#039;&amp;lt;code&amp;gt;[http://docs.marklogic.com/cts:element-query cts:element-query]&amp;lt;/code&amp;gt;&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
*&#039;&#039;&#039;&amp;lt;code&amp;gt;[http://docs.marklogic.com/cts:document-fragment-query cts:document-fragment-query]&amp;lt;/code&amp;gt;&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
*&#039;&#039;&#039;&amp;lt;code&amp;gt;[http://docs.marklogic.com/cts:locks-query cts:locks-query]&amp;lt;/code&amp;gt;&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
*&#039;&#039;&#039;&amp;lt;code&amp;gt;[http://docs.marklogic.com/cts:properties-query cts:properties-query]&amp;lt;/code&amp;gt;&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
*&#039;&#039;&#039;&amp;lt;code&amp;gt;[http://docs.marklogic.com/cts:near-query cts:near-query]&amp;lt;/code&amp;gt;&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Training Resources for MarkLogic Search ==&lt;br /&gt;
* [http://developer.marklogic.com/blog/grokking-the-cts-api &amp;quot;Grokking the cts API&amp;quot;] is a great overview of MarkLogic&#039;s search and query capabilities.&lt;br /&gt;
&lt;br /&gt;
[[Category: MarkLogic]]&lt;/div&gt;</summary>
		<author><name>Bowersmt</name></author>
	</entry>
	<entry>
		<id>https://tech.churchofjesuschrist.org/wiki/index.php?title=MarkLogic_Query_and_Search&amp;diff=70574</id>
		<title>MarkLogic Query and Search</title>
		<link rel="alternate" type="text/html" href="https://tech.churchofjesuschrist.org/wiki/index.php?title=MarkLogic_Query_and_Search&amp;diff=70574"/>
		<updated>2014-11-18T15:21:28Z</updated>

		<summary type="html">&lt;p&gt;Bowersmt: Minor changes&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[[MarkLogic|« Back to MarkLogic]]&lt;br /&gt;
&lt;br /&gt;
== Searching and Querying MarkLogic ==&lt;br /&gt;
Indexes are central to everything you do in MarkLogic.  They are central to how MarkLogic stores data, scales massively, and processes data quickly. They are central to how you develop because you have to use MarkLogic&#039;s indexes to query and search documents. You have to understand how MarkLogic&#039;s indexes work to be able to create fast queries. And you have to know how to model document structure to work best with indexes.&lt;br /&gt;
&lt;br /&gt;
=== How does MarkLogic compare to a relational database? ===&lt;br /&gt;
A document in MarkLogic is very much like a row in a relational database, and a document type ties documents together like a table ties rows together. MarkLogic collections group documents together in any way you want. Collections are like views in a relational database, which group together a filtered set of rows from one or more tables, but collections do not join and merge document content and views cannot arbitrarily include any row from any table. A document in MarkLogic can have a flat structure like a relational table, or it can contain complex nestings of data.  Each nesting of data in a document represents another table in a relational database. For example, a single document in MarkLogic may represent many relational tables, and how they are nested represents their one-to-one, many-to-one, and many-to-many relationships.  &lt;br /&gt;
&lt;br /&gt;
Both MarkLogic and relational databases use indexes to resolve queries without having to scan through all documents or rows. MarkLogic indexes are designed to find any word, phrase, value, element, or element structure -- no matter where it occurs in document structure, no matter how many times it occurs within a document, and no matter what type of document contains it. For example, you can search for and return a &amp;lt;title&amp;gt; element and MarkLogic will return the contents of all &amp;lt;title&amp;gt; elements it finds — even if &amp;lt;title&amp;gt; elements are in different types of documents. This is similar to doing a union query across multiple tables in relational databases. &lt;br /&gt;
&lt;br /&gt;
MarkLogic indexes also let you search for words, phrases, values, elements, or element structures in very specific locations, such as in only certain types of documents or within certain document structures, or in specific collections or folders. For example, you can search for and return all &amp;lt;title&amp;gt; elements that are found in the header section of poetry documents in the Shakespeare and Tennyson collections. &lt;br /&gt;
&lt;br /&gt;
MarkLogic is not designed for joining documents like a relational database.  A relational join searches for matching values across two or more tables and then merges matching rows into a single row. This can be done in MarkLogic, but you have to write advanced code to iterate through query results to match values across different document types, and merge matching documents into a single document. Also since MarkLogic documents are often nested structures, you can&#039;t simply merge them, you have to copy nested content from one document into a specific nested location in another.&lt;br /&gt;
&lt;br /&gt;
Unlike relational databases, MarkLogic can&#039;t do full table scans; queries must use indexes. In contrast, relational databases often use a full table scan to retrieve every row in a table. A rule of thumb in relational databases is that it is faster to directly read in &#039;&#039;all&#039;&#039; the rows when a query accesses more than roughly 25% of the rows. This is because relational databases use variations of the B-Tree index, which requires 3-4 random IOs to find one row and 1 IO to retrieve the row: this is 4-5 total IOs per row.  B-Tree indexes work best for single row lookups, but they become increasingly costly the more rows they retrieve. If an index has to lookup 25% of its rows with 4 IOs per row, the database will do the same amount of IO if it reads in all of the rows (1 IO per row). Since sequential IO on disks is faster than random IO, relational databases prefer full table scans when accessing more than about 25% of rows in a table. On analytical data warehouses, full table scans are always preferred.  &lt;br /&gt;
&lt;br /&gt;
In addition, a relational database [https://docs.oracle.com/database/121/TGSQL/tgsql_optop.htm#TGSQL234 often directly scans through index data] rather than stepping through its B-Tree structure. Databases use a variety of index scans: full scans, range scans, skip scans, join scans, etc. This is index and table records are stored sequentially on disk. This often makes it faster to take advantage of the speed of sequential disk IO and directly load all index or table rows into RAM and process them in RAM; as opposed to walking a b-tree structure and doing multiple slow random IOs to retrieve each record. For the same reason, row and index scans work well in columnar NoSQL databases.&lt;br /&gt;
&lt;br /&gt;
=== Why do MarkLogic queries have to use Indexes? ===&lt;br /&gt;
To maximize parallelism and to spread processing throughout a cluster, MarkLogic spreads documents across the cluster. MarkLogic automatically creates multiple shards per server and spreads them across all the servers in the cluster. Documents are placed in a shard in the order they are created or modified; thus, documents of all types may be randomly intermixed in a shard. Since a shard is not organized by document type, doing a sequential scan to resolve a query would require retrieving and processing all documents in the database. Full scans are not practical in MarkLogic. All queries and searches need to use indexes. For this reason, MarkLogic automatically indexes almost everything. You can also create additional specialized indexes.  MarkLogic indexes are not B-Tree indexes; they are designed to be sharded and queried in parallel across stands, forests, and a database cluster that spans many servers.&lt;br /&gt;
&lt;br /&gt;
=== How does MarkLogic scale horizontally? ===&lt;br /&gt;
Documents in MarkLogic belong to a database. Within a database are one or more servers.  Each server may contain zero or more &amp;quot;forests&amp;quot;. Within each forest are one or more &amp;quot;stands&amp;quot;. Within each stand are one or more &amp;quot;trees&amp;quot;. A document is hierarchical so it is called a &amp;quot;tree&amp;quot;.  (MarkLogic uses the terms &amp;quot;stand&amp;quot; and &amp;quot;forest&amp;quot; instead of &amp;quot;shard&amp;quot;, but they have the same meaning.) &lt;br /&gt;
&lt;br /&gt;
A client contacts one of the servers in a MarkLogic cluster and initiates a query or search. Because MarkLogic communicates through REST web services, a load balancer can spread requests across the servers in a MarkLogic cluster.  The initiating server does the following&lt;br /&gt;
#It validates the query request from the client&lt;br /&gt;
#It parses and optimizes the query &lt;br /&gt;
#It sends the query to all servers that have forests in the database&lt;br /&gt;
##Each server sends it to its forests &lt;br /&gt;
##Each forest sends it to each stand &lt;br /&gt;
##Each stand uses its indexes to find matching documents&lt;br /&gt;
###All stands and forests query the indexes in parallel&lt;br /&gt;
##Forests combine the matching document IDs from all their stands&lt;br /&gt;
##Forests sort the matching document IDs (in relevance score order or value order)&lt;br /&gt;
##When complete, each forest returns a sorted iterator to the initiating server&lt;br /&gt;
#When each forest has returned an iterator&lt;br /&gt;
#It walks the sorted iterators from all the forests and combines the results in sorted &lt;br /&gt;
#It retrieves matching documents from its &#039;&#039;Expanded Tree Cache&#039;&#039; or from the forests when documents are not cached&lt;br /&gt;
##forests retrieve documents from their &#039;&#039;Compressed Tree Cache&#039;&#039; or from disk when documents are not cached&lt;br /&gt;
#It filters returned documents to remove false positive matches &lt;br /&gt;
#It optionally transforms documents &lt;br /&gt;
##It creates new documents by extracting matching elements, changing structure, changing file format, etc.&lt;br /&gt;
#It returns all matching (optionally transformed) documents to the requester&lt;br /&gt;
#It saves resulting document IDs when paging query results, so it can return subsequent pages of matching documents in subsequent requests&lt;br /&gt;
&lt;br /&gt;
The initiating server&#039;s process is CPU intensive, serialized, and blocks while waiting on forests. To prevent this from being a bottleneck to the cluster, you can dedicate nodes in the cluster to do nothing but evaluate queries. These are called e-nodes (evaluation nodes). These nodes don&#039;t hold data. If they held data, the &#039;&#039;serialized&#039;&#039; evaluation process would compete with the &#039;&#039;parallel&#039;&#039; index matching process.  Instead e-nodes are dedicated to validating, parsing, sorting, filtering, transforming, and paginating documents. They cache documents in the &#039;&#039;Expanded Tree Cache&#039;&#039; to minimize the number of documents they have to retrieve from data nodes (d-nodes). D-nodes only do parallel index processing and sorting. They cache documents in their &#039;&#039;Compressed Tree Cache&#039;&#039; to reduce disk IO. &lt;br /&gt;
&lt;br /&gt;
=== How do you optimize a MarkLogic cluster to run queries faster? ===&lt;br /&gt;
*E-nodes and d-nodes can be scaled independently to match the load. &lt;br /&gt;
*You can optimize an e-node by minimizing its &#039;&#039;Compressed Tree Cache&#039;&#039; and maximizing its &#039;&#039;Expanded Tree Cache&#039;&#039;. An e-node needs a big &#039;&#039;Expanded Tree Cache&#039;&#039; so it doesn&#039;t have to retrieve as many documents from d-nodes. An e-node doesn&#039;t need a &#039;&#039;Compressed Tree Cache&#039;&#039; because it doesn&#039;t have any data.&lt;br /&gt;
*You can optimize a d-node by doing the opposite of the e-node: maximize the &#039;&#039;Compressed Tree Cache&#039;&#039; and minimize the &#039;&#039;Expanded Tree Cache&#039;&#039;. You can also optimize d-nodes by making sure each d-node runs on similar hardware and that each forest has a similar number of documents. This is important because all forests process queries in parallel and the slowest forest holds up each query: e-nodes have to wait until the slowest forest finishes.&lt;br /&gt;
*You can optimize a query by making it unfiltered.&lt;br /&gt;
**This means it is completely resolved by the indexes. Because no filtering is required, the initiating server doesn&#039;t have to verify that documents match.&lt;br /&gt;
*You can optimize a query by eliminating false positives.  &lt;br /&gt;
**False positives occur when a query identifies a possible match for a document, but it cannot prove it is a match until the filtering process opens the document and verifies it. &lt;br /&gt;
**False positives happen because MarkLogic only partially indexes certain document items. MarkLogic cannot index everything because it would take too much time and space. For example, MarkLogic has a structure index. It indexes relationships between elements in a document.  MarkLogic cannot afford to index each element&#039;s path from itself to every other element. MarkLogic compromises on indexing only parent/child relationships. This is effective in eliminating most non-matching documents, but it can produce false positives.  The only way to know if a document is an &#039;&#039;exact&#039;&#039; match, MarkLogic must open the document and verify it.&lt;br /&gt;
**For example, suppose a query searches for the following path: &amp;lt;br&amp;gt;&amp;lt;code&amp;gt;books/poetry/poem&amp;lt;/code&amp;gt;&amp;lt;br&amp;gt; The structure index will match documents containing books/poetry and poetry/poem. The resulting documents are a probable match, but could contain false positives, such as &amp;lt;br&amp;gt;&amp;lt;code&amp;gt;books/poetry/fantasy/poetry/poem&amp;lt;/code&amp;gt;.&lt;br /&gt;
**You can eliminate false positive structures queries by giving elements unique names. They are  unique no matter where in they are in the structure and they are more self-descriptive.  Instead of naming an element &amp;quot;line&amp;quot; which can mean many things, you can use the precise name  &amp;quot;poemTextLine&amp;quot;. &lt;br /&gt;
*You can optimize a query by greatly limiting how many documents it matches. Design each query to return as few documents as possible. &lt;br /&gt;
**It is expensive to transmit documents. Matching documents have to travel from stands to forests to the initiating server, and to the requester. &lt;br /&gt;
**It is expensive to process documents on the initiating server and the requester. &lt;br /&gt;
**It takes processing time on d-nodes to compare lists of document IDs. The fewer the matching document IDs in one part of the query, the faster the entire query runs. &lt;br /&gt;
**The more matching document IDs, the more work MarkLogic has to do in a d-node to compare, union, intersect, and subract them from matching document IDs returned by other parts of the query. &lt;br /&gt;
**The more matching document IDs, the more sorting MarkLogic has to do in the stands, forests, and initiating server.&lt;br /&gt;
&lt;br /&gt;
=== How does a MarkLogic query compare to map/reduce? ===&lt;br /&gt;
A MarkLogic query or search is similar to map/reduce.  When you query or search for documents in a database, MarkLogic spreads the work across all the servers to be executed in parallel. This is like a &#039;&#039;map&#039;&#039; process because indexes filter out non-matching documents by combining term, range, and semantic indexes according to the query map. The results are then &#039;&#039;reduced&#039;&#039; at the forest level and again at the database level and again at the initiating server. This parallel division of responsibilities enables MarkLogic to scale.&lt;br /&gt;
&lt;br /&gt;
== Term, Range, and Semantic Indexes ==&lt;br /&gt;
MarkLogic indexes are not B-Tree indexes. MarkLogic uses &#039;&#039;&#039;term&#039;&#039;&#039;, &#039;&#039;&#039;range&#039;&#039;&#039;, and &#039;&#039;&#039;semantic&#039;&#039;&#039; indexes. &lt;br /&gt;
*&#039;&#039;&#039;A term index&#039;&#039;&#039; associates a term with every document that contains the term.  For example, in a word index, every word in the database is stored in the index. Associated with each word in the index is a list of each document ID that contains the term.  &lt;br /&gt;
*&#039;&#039;&#039;A range index&#039;&#039;&#039; is a double term index: it contains each term and all document IDs that contain that term, and it contains each document ID and all the terms that are in the document.&lt;br /&gt;
*&#039;&#039;&#039;A semantic index&#039;&#039;&#039; is similar to a range index but it is optimized to store triples (three pieces of data: subject, object, and predicate).&lt;br /&gt;
&lt;br /&gt;
Term indexes are fast. Give the index a term, and with one lookup, it returns &#039;&#039;all&#039;&#039; documents that contain the term. Term indexes are memory mapped files. They run in RAM unless you run out of RAM and then firmware in the CPU efficiently swaps them to and from disk. Thus, it is best to have enough RAM in a MarkLogic server to contain all indexes in memory.&lt;br /&gt;
&lt;br /&gt;
Unlike B-Tree indexes, term indexes are easily sharded within and between servers. MarkLogic takes advantage of this to run queries in parallel within and across servers. This is how MarkLogic can scale to billions of documents and still return queries and searches in milliseconds.&lt;br /&gt;
&lt;br /&gt;
When documents are inserted or updated, MarkLogic indexes them in RAM (as well as appends the changes to a journal on disk). When documents in RAM start to consume too much RAM, MarkLogic writes them to disk as a &amp;quot;stand&amp;quot; in a &amp;quot;forest&amp;quot; and starts creating a new &amp;quot;stand&amp;quot; in RAM.  &lt;br /&gt;
&lt;br /&gt;
When you query or search for documents, MarkLogic goes to the indexes in the stands (which are cached in RAM) and evaluates the query in parallel. Each stand index returns a list of document IDs (a list of numbers) that match the query. MarkLogic takes the document IDs returned by each stand and merges them into a final list of document IDs, whcih it uses to retrieve the documents from cache or disk. This works well because computers are very fast at sort merging lists of numbers.&lt;br /&gt;
&lt;br /&gt;
MarkLogic uses the same indexes for both queries and searches. This allows you to combine search and query expressions. The main difference between search and query is how documents are sorted: searches sort by relevance and queries sort by values. Another difference is that queries tend to use value indexes and searches tend to use word and phrase indexes. &lt;br /&gt;
&lt;br /&gt;
=== What specific indexes does MarkLogic have? ===&lt;br /&gt;
MarkLogic uses indexes to extract words, values, structures, and links out of documents. An index is an altered view of a document. It enables you to search and query for documents &amp;lt;br&amp;gt;&#039;&#039;&#039;as if they contained only:&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
*&#039;&#039;&#039;Words:&#039;&#039;&#039; a flat set of words without structure, such as &amp;lt;br&amp;gt;&amp;lt;code&amp;gt;[&amp;quot;Mary&amp;quot;, &amp;quot;had&amp;quot;, &amp;quot;a&amp;quot;, &amp;quot;little&amp;quot;, &amp;quot;lamb&amp;quot;]&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
*&#039;&#039;&#039;Phrases:&#039;&#039;&#039; a flat set of phrases without structure, such as &amp;lt;br&amp;gt;&amp;lt;code&amp;gt;[&amp;quot;Mary had&amp;quot;, &amp;quot;had a&amp;quot;, &amp;quot;a little&amp;quot;, &amp;quot;little lamb&amp;quot;]&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
*&#039;&#039;&#039;Elements:&#039;&#039;&#039; a flat set of elements without values, such as &amp;lt;br&amp;gt;&amp;lt;code&amp;gt;[&amp;quot;poem&amp;quot;, &amp;quot;text&amp;quot;, &amp;quot;line&amp;quot;]&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
*&#039;&#039;&#039;Element-values:&#039;&#039;&#039; a flat set of elements with string values, such as &amp;lt;br&amp;gt;&amp;lt;code&amp;gt;&amp;quot;line&amp;quot;: &amp;quot;Mary had a little lamb&amp;quot;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
*&#039;&#039;&#039;Element-words:&#039;&#039;&#039; a flat set of elements with words, such as &amp;lt;br&amp;gt;&amp;lt;code&amp;gt;&amp;quot;line&amp;quot;: [&amp;quot;Mary&amp;quot;, &amp;quot;had&amp;quot;, &amp;quot;a&amp;quot;, &amp;quot;little&amp;quot;, &amp;quot;lamb&amp;quot;]&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
*&#039;&#039;&#039;Element-phrases:&#039;&#039;&#039; a flat set of elements with phrases, such as &amp;lt;br&amp;gt;&amp;lt;code&amp;gt;&amp;quot;line&amp;quot;: [&amp;quot;Mary had&amp;quot;, &amp;quot;had a&amp;quot;, &amp;quot;a little&amp;quot;, &amp;quot;little lamb&amp;quot;]&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
*&#039;&#039;&#039;Element-value lexicon:&#039;&#039;&#039; a flat set of elements with typed values, such as &amp;lt;br&amp;gt;&amp;lt;code&amp;gt;&amp;quot;lineSequence&amp;quot;: 3&amp;lt;/code&amp;gt;&amp;lt;br&amp;gt; or a list, count, or co-occurrence of element values scoped to a database, set of documents, or one document.&lt;br /&gt;
&lt;br /&gt;
*&#039;&#039;&#039;XPath-structure-value lexicon:&#039;&#039;&#039; a flat set of hierarchical elements with typed values, such as &amp;lt;br&amp;gt;&amp;lt;code&amp;gt;poem.text.line.lineSequence: 3&amp;lt;/code&amp;gt;&amp;lt;br&amp;gt; or a list, count, or co-occurrence of hierarchical element values scoped to a database, set of documents, or one document.&lt;br /&gt;
&lt;br /&gt;
*&#039;&#039;&#039;XPath-structure:&#039;&#039;&#039;hierarchical structures without values, such as &amp;lt;br&amp;gt;&amp;lt;code&amp;gt;poem.text.line&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
*&#039;&#039;&#039;XPath-structure-words:&#039;&#039;&#039; hierarchical structures with words, such as &amp;lt;br&amp;gt;&amp;lt;code&amp;gt;poem.text.line: [&amp;quot;Mary&amp;quot;, &amp;quot;had&amp;quot;, &amp;quot;a&amp;quot;, &amp;quot;little&amp;quot;, &amp;quot;lamb&amp;quot;]&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
*&#039;&#039;&#039;XPath-structure-phrases:&#039;&#039;&#039; hierarchical structures with phrases, such as &amp;lt;br&amp;gt;&amp;lt;code&amp;gt;poem.text.line: [&amp;quot;Mary had&amp;quot;, &amp;quot;had a&amp;quot;, &amp;quot;a little&amp;quot;, &amp;quot;little lamb&amp;quot;]&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
*&#039;&#039;&#039;XPath-structure-values:&#039;&#039;&#039; hierarchical structures with values, such as &amp;lt;br&amp;gt;&amp;lt;code&amp;gt;poem.text.line: &amp;quot;Mary had a little lamb&amp;quot;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
*&#039;&#039;&#039;RDF document links&#039;&#039;&#039; to other documents, such as &amp;lt;br&amp;gt;&amp;lt;code&amp;gt;{&amp;quot;subject&amp;quot;: &amp;quot;http://example.org/documents/thisDoc&amp;quot;, &amp;lt;br&amp;gt;&amp;quot;predicate&amp;quot;: &amp;quot;http://example.org/predicates/relatesSomehowTo&amp;quot;, &amp;lt;br&amp;gt;&amp;quot;object&amp;quot;: &amp;quot;http://example.org/documents/thatDoc&amp;quot;}&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
*&#039;&#039;&#039;RDF abstract links&#039;&#039;&#039; to other abstract concepts, such as &amp;lt;br&amp;gt;&amp;lt;code&amp;gt;{&amp;quot;subject&amp;quot;: &amp;quot;http://example.org/documents/thisDoc&amp;quot;, &amp;lt;br&amp;gt;&amp;quot;predicate&amp;quot;: &amp;quot;http://example.org/predicates/relatesSomehowTo&amp;quot;, &amp;lt;br&amp;gt;&amp;quot;object&amp;quot;: &amp;quot;http://example.org/documents/someConceptWithNoDocumentAtTheURI&amp;quot;}&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
*&#039;&#039;&#039;RDF data links&#039;&#039;&#039; to data, such as &amp;lt;br&amp;gt;&amp;lt;code&amp;gt;{&amp;quot;subject&amp;quot;: &amp;quot;http://example.org/documents/thisDoc&amp;quot;, &amp;lt;br&amp;gt;&amp;quot;predicate&amp;quot;: &amp;quot;http://example.org/predicates/ageInYears&amp;quot;, &amp;lt;br&amp;gt;&amp;quot;object&amp;quot;: 12}&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
MarkLogic can combine any of these indexes in any way to find matching documents.  It can sort the result by relevance or by value. &lt;br /&gt;
&lt;br /&gt;
Search and query expressions are fully composable; i.e. they can be nested inside each other and combined using AND, OR, and NOT expressions.&lt;br /&gt;
&lt;br /&gt;
== Search Functions in MarkLogic ==&lt;br /&gt;
=== Executing a Search ===&lt;br /&gt;
*&#039;&#039;&#039;&amp;lt;code&amp;gt;[http://docs.marklogic.com/cts:search cts:search]&amp;lt;/code&amp;gt;&#039;&#039;&#039; is the most important function because it executes a search and returns matching nodes. &lt;br /&gt;
**&#039;&#039;&#039;You must include an XPath expression&#039;&#039;&#039; to define which nodes to &#039;&#039;search&#039;&#039; and &#039;&#039;return&#039;&#039;. &lt;br /&gt;
**The search returns &#039;&#039;nodes&#039;&#039;, which can be documents, elements, attributes, or text. Thus, a search doesn&#039;t have to return entire documents. Depending on the scope of your XPath statement, it may return entire documents, or one matching node from each document, or many matching nodes from each document.  &lt;br /&gt;
**&#039;&#039;&#039;You must include a cts query expression&#039;&#039;&#039; to filter the contents of &#039;&#039;nodes&#039;&#039; selected by the XPath expression. This allows you to search for specific content within specific nodes and return only those nodes that contain that content. If you want to return all the nodes selected by the XPath expression, you can use the empty query expression: &amp;lt;code&amp;gt;cts:and-query(())&amp;lt;/code&amp;gt;.&lt;br /&gt;
**You may limit the search to specific forests. You may set options like unfiltered, faceted, unchecked, quality weight, relevance scoring method, and relevance trace.&lt;br /&gt;
**Use Cases:&lt;br /&gt;
***A search can return entire documents whose contents match the XPath and query expressions.&lt;br /&gt;
***A search can extract and return titles from documents as long as the contents of the titles match the XPath and query expressions.&lt;br /&gt;
***A search can extract and return all the paragraphs from documents as long as the contents of the paragraphs match the XPath and query expressions.&lt;br /&gt;
**Notes:&lt;br /&gt;
***There is no functional difference between searching entire documents and elements because an element has the same structure as document.  Both may contain complex nested elements or both may simply contain a value. In both cases, MarkLogic retrieves entire documents. In the case of elements, it extracts the requested elements from each retrieved document.&lt;br /&gt;
***Searching attributes, text nodes, and childless elements is similar to searching documents and elements with children — except the cts query cannot look for nested structures.&lt;br /&gt;
&lt;br /&gt;
*&#039;&#039;&#039;&amp;lt;code&amp;gt;[http://docs.marklogic.com/cts:contains cts:contains]&amp;lt;/code&amp;gt;&#039;&#039;&#039; is the second most important function because it returns true when a cts query finds at least one matching node in the nodes returned by an XPath expression (or a sequence of values). In other words, it returns true when at least one of the specified nodes &#039;&#039;&#039;contains&#039;&#039;&#039; the precise combination of words, phrases, values, structures, and/or triples in a cts query.&lt;br /&gt;
&lt;br /&gt;
=== Constructing a Query ===&lt;br /&gt;
You compose a query using cts query constructor functions. You then execute the query by passing it into &amp;lt;code&amp;gt;cts:search, cts:contains, search:search&amp;lt;/code&amp;gt;, and lexicon functions. MarkLogic has 30+ query constructors. They all end in &#039;&#039;&#039;&amp;quot;-query&amp;quot;&#039;&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
==== Composite Query Constructors ====&lt;br /&gt;
The composite query constructors build up new queries from other queries, and queries can be nested within queries.&lt;br /&gt;
&lt;br /&gt;
*&#039;&#039;&#039;&amp;lt;code&amp;gt;[http://docs.marklogic.com/cts:and-query cts:and-query]&amp;lt;/code&amp;gt;&#039;&#039;&#039; returns a query that intersects two or more sub-queries. You may optionally specify an &amp;quot;ordered&amp;quot; option that requires document contents to match sub-queries in the order they are listed; for example if the sub-queries are &amp;quot;To be&amp;quot; and &amp;quot;or not to be&amp;quot;, then the query will match documents that have the phrase &amp;quot;To be&amp;quot; &#039;&#039;before&#039;&#039; &amp;quot;or not to be&amp;quot;. The default is &amp;quot;unordered&amp;quot;, which allows each sub-query to match the content in any order that it occurs in the document.  If you pass in the empty sequence, such as &amp;lt;code&amp;gt;cts:and-query(())&amp;lt;/code&amp;gt;, then it will match every document in the database.&lt;br /&gt;
&lt;br /&gt;
*&#039;&#039;&#039;&amp;lt;code&amp;gt;[http://docs.marklogic.com/cts:or-query cts:or-query]&amp;lt;/code&amp;gt;&#039;&#039;&#039; returns a query that unions two or more sub-queries.&lt;br /&gt;
&lt;br /&gt;
*&#039;&#039;&#039;&amp;lt;code&amp;gt;[http://docs.marklogic.com/cts:not-query cts:not-query]&amp;lt;/code&amp;gt;&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
*&#039;&#039;&#039;&amp;lt;code&amp;gt;[http://docs.marklogic.com/cts:and-not-query cts:and-not-query]&amp;lt;/code&amp;gt;&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
*&#039;&#039;&#039;&amp;lt;code&amp;gt;[http://docs.marklogic.com/cts:element-query cts:element-query]&amp;lt;/code&amp;gt;&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
*&#039;&#039;&#039;&amp;lt;code&amp;gt;[http://docs.marklogic.com/cts:document-fragment-query cts:document-fragment-query]&amp;lt;/code&amp;gt;&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
*&#039;&#039;&#039;&amp;lt;code&amp;gt;[http://docs.marklogic.com/cts:locks-query cts:locks-query]&amp;lt;/code&amp;gt;&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
*&#039;&#039;&#039;&amp;lt;code&amp;gt;[http://docs.marklogic.com/cts:properties-query cts:properties-query]&amp;lt;/code&amp;gt;&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
*&#039;&#039;&#039;&amp;lt;code&amp;gt;[http://docs.marklogic.com/cts:near-query cts:near-query]&amp;lt;/code&amp;gt;&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Training Resources for MarkLogic Search ==&lt;br /&gt;
* [http://developer.marklogic.com/blog/grokking-the-cts-api &amp;quot;Grokking the cts API&amp;quot;] is a great overview of MarkLogic&#039;s search and query capabilities.&lt;br /&gt;
&lt;br /&gt;
[[Category: MarkLogic]]&lt;/div&gt;</summary>
		<author><name>Bowersmt</name></author>
	</entry>
	<entry>
		<id>https://tech.churchofjesuschrist.org/wiki/index.php?title=MarkLogic_Query_and_Search&amp;diff=70572</id>
		<title>MarkLogic Query and Search</title>
		<link rel="alternate" type="text/html" href="https://tech.churchofjesuschrist.org/wiki/index.php?title=MarkLogic_Query_and_Search&amp;diff=70572"/>
		<updated>2014-11-15T22:54:25Z</updated>

		<summary type="html">&lt;p&gt;Bowersmt: Added more information about searching&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[[MarkLogic|« Back to MarkLogic]]&lt;br /&gt;
&lt;br /&gt;
== Searching and Querying MarkLogic ==&lt;br /&gt;
Indexes are central to everything you do in MarkLogic.  They are central to how MarkLogic stores data, scales massively, and processes data quickly. They are central to how you develop because you have to use MarkLogic&#039;s indexes to query and search documents. You have to understand how MarkLogic&#039;s indexes work to be able to create fast queries. And you have to know how to model document structure to work best with indexes.&lt;br /&gt;
&lt;br /&gt;
=== How does MarkLogic compare to a relational database? ===&lt;br /&gt;
A document in MarkLogic is very much like a row in a relational database, and a document type ties documents together like a table ties rows together. MarkLogic collections group documents together in any way you want. Collections are like views in a relational database, which group together a filtered set of rows from one or more tables, but collections do not join and merge document content and views cannot arbitrarily include any row from any table. A document in MarkLogic can have a flat structure like a relational table, or it can contain complex nestings of data.  Each nesting of data in a document represents another table in a relational database. For example, a single document in MarkLogic may represent many relational tables, and how they are nested represents their one-to-one, many-to-one, and many-to-many relationships.  &lt;br /&gt;
&lt;br /&gt;
Both MarkLogic and relational databases use indexes to resolve queries without having to scan through all documents or rows. MarkLogic indexes are designed to find any word, phrase, value, element, or element structure -- no matter where it occurs in document structure, no matter how many times it occurs within a document, and no matter what type of document contains it. For example, you can search for and return a &amp;lt;title&amp;gt; element and MarkLogic will return the contents of all &amp;lt;title&amp;gt; elements it finds — even if &amp;lt;title&amp;gt; elements are in different types of documents. This is similar to doing a union query across multiple tables in relational databases. &lt;br /&gt;
&lt;br /&gt;
MarkLogic indexes also let you search for words, phrases, values, elements, or element structures in very specific locations, such as in only certain types of documents or within certain document structures, or in specific collections or folders. For example, you can search for and return all &amp;lt;title&amp;gt; elements that are found in the header section of poetry documents in the Shakespeare and Tennyson collections. &lt;br /&gt;
&lt;br /&gt;
MarkLogic is not designed for joining documents like a relational database.  A relational join searches for matching values across two or more tables and then merges matching rows into a single row. This can be done in MarkLogic, but you have to write advanced code to iterate through query results to match values across different document types, and merge matching documents into a single document. Also since MarkLogic documents are often nested structures, you can&#039;t simply merge them, you have to copy nested content from one document into a specific nested location in another.&lt;br /&gt;
&lt;br /&gt;
Unlike relational databases, MarkLogic can&#039;t do full table scans; queries must use indexes. In contrast, relational databases often use a full table scan to retrieve every row in a table. A rule of thumb in relational databases is that it is faster to directly read in &#039;&#039;all&#039;&#039; the rows when a query accesses more than roughly 25% of the rows. This is because relational databases use variations of the B-Tree index, which requires 3-4 random IOs to find one row and 1 IO to retrieve the row: this is 4-5 total IOs per row.  B-Tree indexes work best for single row lookups, but they become increasingly costly the more rows they retrieve. If an index has to lookup 25% of its rows with 4 IOs per row, the database will do the same amount of IO if it reads in all of the rows (1 IO per row). Since sequential IO on disks is faster than random IO, relational databases prefer full table scans when accessing more than about 25% of rows in a table. On analytical data warehouses, full table scans are always preferred.  &lt;br /&gt;
&lt;br /&gt;
In addition, a relational database [https://docs.oracle.com/database/121/TGSQL/tgsql_optop.htm#TGSQL234 often directly scans through index data] rather than stepping through its B-Tree structure. Databases use a variety of index scans: full scans, range scans, skip scans, join scans, etc. This is index and table records are stored sequentially on disk. This often makes it faster to take advantage of the speed of sequential disk IO and directly load all index or table rows into RAM and process them in RAM; as opposed to walking a b-tree structure and doing multiple slow random IOs to retrieve each record. For the same reason, row and index scans work well in columnar NoSQL databases.&lt;br /&gt;
&lt;br /&gt;
=== Why do MarkLogic queries have to use Indexes? ===&lt;br /&gt;
To maximize parallelism and to spread processing throughout a cluster, MarkLogic spreads documents across the cluster. MarkLogic automatically creates multiple shards per server and spreads them across all the servers in the cluster. Documents are placed in a shard in the order they are created or modified; thus, documents of all types may be randomly intermixed in a shard. Since a shard is not organized by document type, doing a sequential scan to resolve a query would require retrieving and processing all documents in the database. Full scans are not practical in MarkLogic. All queries and searches need to use indexes. For this reason, MarkLogic automatically indexes almost everything. You can also create additional specialized indexes.  MarkLogic indexes are not B-Tree indexes; they are designed to be sharded and queried in parallel across stands, forests, and a database cluster that spans many servers.&lt;br /&gt;
&lt;br /&gt;
=== How does MarkLogic scale horizontally? ===&lt;br /&gt;
Documents in MarkLogic belong to a database. Within a database are one or more servers.  Each server may contain zero or more &amp;quot;forests&amp;quot;. Within each forest are one or more &amp;quot;stands&amp;quot;. Within each stand are one or more &amp;quot;trees&amp;quot;. A document is hierarchical so it is called a &amp;quot;tree&amp;quot;.  (MarkLogic uses the terms &amp;quot;stand&amp;quot; and &amp;quot;forest&amp;quot; instead of &amp;quot;shard&amp;quot;, but they have the same meaning.) &lt;br /&gt;
&lt;br /&gt;
A client contacts one of the servers in a MarkLogic cluster and initiates a query or search. Because MarkLogic communicates through REST web services, a load balancer can spread requests across the servers in a MarkLogic cluster.  The initiating server does the following&lt;br /&gt;
#It validates the query request from the client&lt;br /&gt;
#It parses and optimizes the query &lt;br /&gt;
#It sends the query to all servers that have forests in the database&lt;br /&gt;
##Each server sends it to its forests &lt;br /&gt;
##Each forest sends it to each stand &lt;br /&gt;
##Each stand uses its indexes to find matching documents&lt;br /&gt;
###All stands and forests query the indexes in parallel&lt;br /&gt;
##Forests combine the matching document IDs from all their stands&lt;br /&gt;
##Forests sort the matching document IDs (in relevance score order or value order)&lt;br /&gt;
##When complete, each forest returns a sorted iterator to the initiating server&lt;br /&gt;
#When each forest has returned an iterator&lt;br /&gt;
#It walks the sorted iterators from all the forests and combines the results in sorted &lt;br /&gt;
#It retrieves matching documents from its &#039;&#039;Expanded Tree Cache&#039;&#039; or from the forests when documents are not cached&lt;br /&gt;
##forests retrieve documents from their &#039;&#039;Compressed Tree Cache&#039;&#039; or from disk when documents are not cached&lt;br /&gt;
#It filters returned documents to remove false positive matches &lt;br /&gt;
#It optionally transforms documents &lt;br /&gt;
##It creates new documents by extracting matching elements, changing structure, changing file format, etc.&lt;br /&gt;
#It returns all matching (optionally transformed) documents to the requester&lt;br /&gt;
#It saves resulting document IDs when paging query results, so it can return subsequent pages of matching documents in subsequent requests&lt;br /&gt;
&lt;br /&gt;
The initiating server&#039;s process is CPU intensive, serialized, and blocks while waiting on forests. To prevent this from being a bottleneck to the cluster, you can dedicate nodes in the cluster to do nothing but evaluate queries. These are called e-nodes (evaluation nodes). These nodes don&#039;t hold data. If they held data, the &#039;&#039;serialized&#039;&#039; evaluation process would compete with the &#039;&#039;parallel&#039;&#039; index matching process.  Instead e-nodes are dedicated to validating, parsing, sorting, filtering, transforming, and paginating documents. They cache documents in the &#039;&#039;Expanded Tree Cache&#039;&#039; to minimize the number of documents they have to retrieve from data nodes (d-nodes). D-nodes only do parallel index processing and sorting. They cache documents in their &#039;&#039;Compressed Tree Cache&#039;&#039; to reduce disk IO. &lt;br /&gt;
&lt;br /&gt;
=== How do you optimize a MarkLogic cluster to run queries faster? ===&lt;br /&gt;
*E-nodes and d-nodes can be scaled independently to match the load. &lt;br /&gt;
*You can optimize an e-node by minimizing its &#039;&#039;Compressed Tree Cache&#039;&#039; and maximizing its &#039;&#039;Expanded Tree Cache&#039;&#039;. An e-node needs a big &#039;&#039;Expanded Tree Cache&#039;&#039; so it doesn&#039;t have to retrieve as many documents from d-nodes. An e-node doesn&#039;t need a &#039;&#039;Compressed Tree Cache&#039;&#039; because it doesn&#039;t have any data.&lt;br /&gt;
*You can optimize a d-node by doing the opposite of the e-node: maximize the &#039;&#039;Compressed Tree Cache&#039;&#039; and minimize the &#039;&#039;Expanded Tree Cache&#039;&#039;. You can also optimize d-nodes by making sure each d-node runs on similar hardware and that each forest has a similar number of documents. This is important because all forests process queries in parallel and the slowest forest holds up each query: e-nodes have to wait until the slowest forest finishes.&lt;br /&gt;
*You can optimize a query by making it unfiltered.&lt;br /&gt;
**This means it is completely resolved by the indexes. Because no filtering is required, the initiating server doesn&#039;t have to verify that documents match.&lt;br /&gt;
*You can optimize a query by eliminating false positives.  &lt;br /&gt;
**False positives occur when a query identifies a possible match for a document, but it cannot prove it is a match until the filtering process opens the document and verifies it. &lt;br /&gt;
**False positives happen because MarkLogic only partially indexes certain document items. MarkLogic cannot index everything because it would take too much time and space. For example, MarkLogic has a structure index. It indexes relationships between elements in a document.  MarkLogic cannot afford to index each element&#039;s path from itself to every other element. MarkLogic compromises on indexing only parent/child relationships. This is effective in eliminating most non-matching documents, but it can produce false positives.  The only way to know if a document is an &#039;&#039;exact&#039;&#039; match, MarkLogic must open the document and verify it.&lt;br /&gt;
**For example, suppose a query searches for the following path: &amp;lt;br&amp;gt;&amp;lt;code&amp;gt;books/poetry/poem&amp;lt;/code&amp;gt;&amp;lt;br&amp;gt; The structure index will match documents containing books/poetry and poetry/poem. The resulting documents are a probable match, but could contain false positives, such as &amp;lt;br&amp;gt;&amp;lt;code&amp;gt;books/poetry/fantasy/poetry/poem&amp;lt;/code&amp;gt;.&lt;br /&gt;
**You can eliminate false positive structures queries by giving elements unique names. They are  unique no matter where in they are in the structure and they are more self-descriptive.  Instead of naming an element &amp;quot;line&amp;quot; which can mean many things, you can use the precise name  &amp;quot;poemTextLine&amp;quot;. &lt;br /&gt;
*You can optimize a query by greatly limiting how many documents it matches. Design each query to return as few documents as possible. &lt;br /&gt;
**It is expensive to transmit documents. Matching documents have to travel from stands to forests to the initiating server, and to the requester. &lt;br /&gt;
**It is expensive to process documents on the initiating server and the requester. &lt;br /&gt;
**It takes processing time on d-nodes to compare lists of document IDs. The fewer the matching document IDs in one part of the query, the faster the entire query runs. &lt;br /&gt;
**The more matching document IDs, the more work MarkLogic has to do in a d-node to compare, union, intersect, and subract them from matching document IDs returned by other parts of the query. &lt;br /&gt;
**The more matching document IDs, the more sorting MarkLogic has to do in the stands, forests, and initiating server.&lt;br /&gt;
&lt;br /&gt;
=== How does a MarkLogic query compare to map/reduce? ===&lt;br /&gt;
A MarkLogic query or search is similar to map/reduce.  When you query or search for documents in a database, MarkLogic spreads the work across all the servers to be executed in parallel. This is like a &#039;&#039;map&#039;&#039; process because indexes filter out non-matching documents by combining term, range, and semantic indexes according to the query map. The results are then &#039;&#039;reduced&#039;&#039; at the forest level and again at the database level and again at the initiating server. This parallel division of responsibilities enables MarkLogic to scale.&lt;br /&gt;
&lt;br /&gt;
== Term, Range, and Semantic Indexes ==&lt;br /&gt;
MarkLogic indexes are not B-Tree indexes. MarkLogic uses &#039;&#039;&#039;term&#039;&#039;&#039;, &#039;&#039;&#039;range&#039;&#039;&#039;, and &#039;&#039;&#039;semantic&#039;&#039;&#039; indexes. &lt;br /&gt;
*&#039;&#039;&#039;A term index&#039;&#039;&#039; associates a term with every document that contains the term.  For example, in a word index, every word in the database is stored in the index. Associated with each word in the index is a list of each document ID that contains the term.  &lt;br /&gt;
*&#039;&#039;&#039;A range index&#039;&#039;&#039; is a double term index: it contains each term and all document IDs that contain that term, and it contains each document ID and all the terms that are in the document.&lt;br /&gt;
*&#039;&#039;&#039;A semantic index&#039;&#039;&#039; is similar to a range index but it is optimized to store triples (three pieces of data: subject, object, and predicate).&lt;br /&gt;
&lt;br /&gt;
Term indexes are fast. Give the index a term, and with one lookup, it returns &#039;&#039;all&#039;&#039; documents that contain the term. Term indexes are memory mapped files. They run in RAM unless you run out of RAM and then firmware in the CPU efficiently swaps them to and from disk. Thus, it is best to have enough RAM in a MarkLogic server to contain all indexes in memory.&lt;br /&gt;
&lt;br /&gt;
Unlike B-Tree indexes, term indexes are easily sharded within and between servers. MarkLogic takes advantage of this to run queries in parallel within and across servers. This is how MarkLogic can scale to billions of documents and still return queries and searches in milliseconds.&lt;br /&gt;
&lt;br /&gt;
When documents are inserted or updated, MarkLogic indexes them in RAM (as well as appends the changes to a journal on disk). When documents in RAM start to consume too much RAM, MarkLogic writes them to disk as a &amp;quot;stand&amp;quot; in a &amp;quot;forest&amp;quot; and starts creating a new &amp;quot;stand&amp;quot; in RAM.  &lt;br /&gt;
&lt;br /&gt;
When you query or search for documents, MarkLogic goes to the indexes in the stands (which are cached in RAM) and evaluates the query in parallel. Each stand index returns a list of document IDs (a list of numbers) that match the query. MarkLogic takes the document IDs returned by each stand and merges them into a final list of document IDs, whcih it uses to retrieve the documents from cache or disk. This works well because computers are very fast at sort merging lists of numbers.&lt;br /&gt;
&lt;br /&gt;
MarkLogic uses the same indexes for both queries and searches. This allows you to combine search and query expressions. The main difference between search and query is how documents are sorted: searches sort by relevance and queries sort by values. Another difference is that queries tend to use value indexes and searches tend to use word and phrase indexes. &lt;br /&gt;
&lt;br /&gt;
=== What specific indexes does MarkLogic have? ===&lt;br /&gt;
MarkLogic uses indexes to extract words, values, structures, and links out of documents. An index is an altered view of a document. It enables you to search and query for documents &amp;lt;br&amp;gt;&#039;&#039;&#039;as if they contained only:&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
*&#039;&#039;&#039;Words:&#039;&#039;&#039; a flat set of words without structure, such as &amp;lt;br&amp;gt;&amp;lt;code&amp;gt;[&amp;quot;Mary&amp;quot;, &amp;quot;had&amp;quot;, &amp;quot;a&amp;quot;, &amp;quot;little&amp;quot;, &amp;quot;lamb&amp;quot;]&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
*&#039;&#039;&#039;Phrases:&#039;&#039;&#039; a flat set of phrases without structure, such as &amp;lt;br&amp;gt;&amp;lt;code&amp;gt;[&amp;quot;Mary had&amp;quot;, &amp;quot;had a&amp;quot;, &amp;quot;a little&amp;quot;, &amp;quot;little lamb&amp;quot;]&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
*&#039;&#039;&#039;Elements:&#039;&#039;&#039; a flat set of elements without values, such as &amp;lt;br&amp;gt;&amp;lt;code&amp;gt;[&amp;quot;poem&amp;quot;, &amp;quot;text&amp;quot;, &amp;quot;line&amp;quot;]&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
*&#039;&#039;&#039;Element-values:&#039;&#039;&#039; a flat set of elements with string values, such as &amp;lt;br&amp;gt;&amp;lt;code&amp;gt;&amp;quot;line&amp;quot;: &amp;quot;Mary had a little lamb&amp;quot;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
*&#039;&#039;&#039;Element-words:&#039;&#039;&#039; a flat set of elements with words, such as &amp;lt;br&amp;gt;&amp;lt;code&amp;gt;&amp;quot;line&amp;quot;: [&amp;quot;Mary&amp;quot;, &amp;quot;had&amp;quot;, &amp;quot;a&amp;quot;, &amp;quot;little&amp;quot;, &amp;quot;lamb&amp;quot;]&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
*&#039;&#039;&#039;Element-phrases:&#039;&#039;&#039; a flat set of elements with phrases, such as &amp;lt;br&amp;gt;&amp;lt;code&amp;gt;&amp;quot;line&amp;quot;: [&amp;quot;Mary had&amp;quot;, &amp;quot;had a&amp;quot;, &amp;quot;a little&amp;quot;, &amp;quot;little lamb&amp;quot;]&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
*&#039;&#039;&#039;Element-value lexicon:&#039;&#039;&#039; a flat set of elements with typed values, such as &amp;lt;br&amp;gt;&amp;lt;code&amp;gt;&amp;quot;lineSequence&amp;quot;: 3&amp;lt;/code&amp;gt;&amp;lt;br&amp;gt; or a list, count, or co-occurrence of element values scoped to a database, set of documents, or one document.&lt;br /&gt;
&lt;br /&gt;
*&#039;&#039;&#039;XPath-structure-value lexicon:&#039;&#039;&#039; a flat set of hierarchical elements with typed values, such as &amp;lt;br&amp;gt;&amp;lt;code&amp;gt;poem.text.line.lineSequence: 3&amp;lt;/code&amp;gt;&amp;lt;br&amp;gt; or a list, count, or co-occurrence of hierarchical element values scoped to a database, set of documents, or one document.&lt;br /&gt;
&lt;br /&gt;
*&#039;&#039;&#039;XPath-structure:&#039;&#039;&#039;hierarchical structures without values, such as &amp;lt;br&amp;gt;&amp;lt;code&amp;gt;poem.text.line&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
*&#039;&#039;&#039;XPath-structure-words:&#039;&#039;&#039; hierarchical structures with words, such as &amp;lt;br&amp;gt;&amp;lt;code&amp;gt;poem.text.line: [&amp;quot;Mary&amp;quot;, &amp;quot;had&amp;quot;, &amp;quot;a&amp;quot;, &amp;quot;little&amp;quot;, &amp;quot;lamb&amp;quot;]&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
*&#039;&#039;&#039;XPath-structure-phrases:&#039;&#039;&#039; hierarchical structures with phrases, such as &amp;lt;br&amp;gt;&amp;lt;code&amp;gt;poem.text.line: [&amp;quot;Mary had&amp;quot;, &amp;quot;had a&amp;quot;, &amp;quot;a little&amp;quot;, &amp;quot;little lamb&amp;quot;]&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
*&#039;&#039;&#039;XPath-structure-values:&#039;&#039;&#039; hierarchical structures with values, such as &amp;lt;br&amp;gt;&amp;lt;code&amp;gt;poem.text.line: &amp;quot;Mary had a little lamb&amp;quot;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
*&#039;&#039;&#039;RDF document links&#039;&#039;&#039; to other documents, such as &amp;lt;br&amp;gt;&amp;lt;code&amp;gt;{&amp;quot;subject&amp;quot;: &amp;quot;http://example.org/documents/thisDoc&amp;quot;, &amp;lt;br&amp;gt;&amp;quot;predicate&amp;quot;: &amp;quot;http://example.org/predicates/relatesSomehowTo&amp;quot;, &amp;lt;br&amp;gt;&amp;quot;object&amp;quot;: &amp;quot;http://example.org/documents/thatDoc&amp;quot;}&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
*&#039;&#039;&#039;RDF abstract links&#039;&#039;&#039; to other abstract concepts, such as &amp;lt;br&amp;gt;&amp;lt;code&amp;gt;{&amp;quot;subject&amp;quot;: &amp;quot;http://example.org/documents/thisDoc&amp;quot;, &amp;lt;br&amp;gt;&amp;quot;predicate&amp;quot;: &amp;quot;http://example.org/predicates/relatesSomehowTo&amp;quot;, &amp;lt;br&amp;gt;&amp;quot;object&amp;quot;: &amp;quot;http://example.org/documents/someConceptWithNoDocumentAtTheURI&amp;quot;}&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
*&#039;&#039;&#039;RDF data links&#039;&#039;&#039; to data, such as &amp;lt;br&amp;gt;&amp;lt;code&amp;gt;{&amp;quot;subject&amp;quot;: &amp;quot;http://example.org/documents/thisDoc&amp;quot;, &amp;lt;br&amp;gt;&amp;quot;predicate&amp;quot;: &amp;quot;http://example.org/predicates/ageInYears&amp;quot;, &amp;lt;br&amp;gt;&amp;quot;object&amp;quot;: 12}&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
MarkLogic can combine any of these indexes in any way to find matching documents.  It can sort the result by relevance or by value. &lt;br /&gt;
&lt;br /&gt;
Search and query expressions are fully composable; i.e. they can be nested inside each other and combined using AND, OR, and NOT expressions.&lt;br /&gt;
&lt;br /&gt;
== Search Functions in MarkLogic ==&lt;br /&gt;
=== Executing a Search ===&lt;br /&gt;
*&#039;&#039;&#039;&amp;lt;code&amp;gt;[http://docs.marklogic.com/cts:search cts:search]&amp;lt;/code&amp;gt;&#039;&#039;&#039; is the most important function because it executes a search and returns matching nodes. &lt;br /&gt;
**&#039;&#039;&#039;You must include an XPath expression&#039;&#039;&#039; to define which nodes to &#039;&#039;search&#039;&#039; and &#039;&#039;return&#039;&#039;. &lt;br /&gt;
**The search returns &#039;&#039;nodes&#039;&#039;, which can be documents, elements, attributes, or text. Thus, a search doesn&#039;t have to return entire documents. Depending on the scope of your XPath statement, it may return entire documents, or one matching node from each document, or many matching nodes from each document.  &lt;br /&gt;
**&#039;&#039;&#039;You must include a cts query expression&#039;&#039;&#039; to filter the contents of &#039;&#039;nodes&#039;&#039; selected by the XPath expression. This allows you to search for specific content within specific nodes and return only those nodes that contain that content. If you want to return all the nodes selected by the XPath expression, you can use the empty query expression: &amp;lt;code&amp;gt;cts:and-query(())&amp;lt;/code&amp;gt;.&lt;br /&gt;
**You may limit the search to specific forests. You may set options like unfiltered, faceted, unchecked, quality weight, relevance scoring method, and relevance trace.&lt;br /&gt;
**Use Cases:&lt;br /&gt;
***A search can return entire documents whose contents match the XPath and query expressions.&lt;br /&gt;
***A search can extract and return titles from documents as long as the contents of the titles match the XPath and query expressions.&lt;br /&gt;
***A search can extract and return all the paragraphs from documents as long as the contents of the paragraphs match the XPath and query expressions.&lt;br /&gt;
**Notes:&lt;br /&gt;
***There is no functional difference between searching entire documents and elements because an element has the same structure as document.  Both may contain complex nested elements or both may simply contain a value. In both cases, MarkLogic retrieves entire documents. In the case of elements, it extracts the requested elements from each retrieved document.&lt;br /&gt;
***Searching attributes, text nodes, and childless elements is similar to searching documents and elements with children — except the cts query cannot look for nested structures.&lt;br /&gt;
&lt;br /&gt;
*&#039;&#039;&#039;&amp;lt;code&amp;gt;[http://docs.marklogic.com/cts:contains cts:contains]&amp;lt;/code&amp;gt;&#039;&#039;&#039; is the second most important function because it returns true when a cts query finds at least one matching node in the nodes returned by an XPath expression (or a sequence of values). In other words, it returns true when at least one of the specified nodes &#039;&#039;&#039;contains&#039;&#039;&#039; the precise combination of words, phrases, values, structures, and/or triples in a cts query.&lt;br /&gt;
&lt;br /&gt;
=== Constructing a Query ===&lt;br /&gt;
You compose a query using cts query constructor functions. You then execute the query by passing it into &amp;lt;code&amp;gt;cts:search, cts:contains, search:search&amp;lt;/code&amp;gt;, and lexicon functions. MarkLogic has 30+ query constructors. They all end in &#039;&#039;&#039;&amp;quot;-query&amp;quot;&#039;&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
==== Composite Query Constructors ====&lt;br /&gt;
The composite query constructors build up new queries from other queries, and queries can be nested within queries.&lt;br /&gt;
&lt;br /&gt;
*&#039;&#039;&#039;&amp;lt;code&amp;gt;[http://docs.marklogic.com/cts:and-query cts:and-query]&amp;lt;/code&amp;gt;&#039;&#039;&#039; returns a query that intersects two or more sub-queries.&lt;br /&gt;
&lt;br /&gt;
*&#039;&#039;&#039;&amp;lt;code&amp;gt;[http://docs.marklogic.com/cts:or-query cts:or-query]&amp;lt;/code&amp;gt;&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
*&#039;&#039;&#039;&amp;lt;code&amp;gt;[http://docs.marklogic.com/cts:not-query cts:not-query]&amp;lt;/code&amp;gt;&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
*&#039;&#039;&#039;&amp;lt;code&amp;gt;[http://docs.marklogic.com/cts:and-not-query cts:and-not-query]&amp;lt;/code&amp;gt;&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
*&#039;&#039;&#039;&amp;lt;code&amp;gt;[http://docs.marklogic.com/cts:element-query cts:element-query]&amp;lt;/code&amp;gt;&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
*&#039;&#039;&#039;&amp;lt;code&amp;gt;[http://docs.marklogic.com/cts:document-fragment-query cts:document-fragment-query]&amp;lt;/code&amp;gt;&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
*&#039;&#039;&#039;&amp;lt;code&amp;gt;[http://docs.marklogic.com/cts:locks-query cts:locks-query]&amp;lt;/code&amp;gt;&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
*&#039;&#039;&#039;&amp;lt;code&amp;gt;[http://docs.marklogic.com/cts:properties-query cts:properties-query]&amp;lt;/code&amp;gt;&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
*&#039;&#039;&#039;&amp;lt;code&amp;gt;[http://docs.marklogic.com/cts:near-query cts:near-query]&amp;lt;/code&amp;gt;&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Training Resources for MarkLogic Search ==&lt;br /&gt;
* [http://developer.marklogic.com/blog/grokking-the-cts-api &amp;quot;Grokking the cts API&amp;quot;] is a great overview of MarkLogic&#039;s search and query capabilities.&lt;br /&gt;
&lt;br /&gt;
[[Category: MarkLogic]]&lt;/div&gt;</summary>
		<author><name>Bowersmt</name></author>
	</entry>
	<entry>
		<id>https://tech.churchofjesuschrist.org/wiki/index.php?title=MarkLogic_Query_and_Search&amp;diff=70571</id>
		<title>MarkLogic Query and Search</title>
		<link rel="alternate" type="text/html" href="https://tech.churchofjesuschrist.org/wiki/index.php?title=MarkLogic_Query_and_Search&amp;diff=70571"/>
		<updated>2014-11-15T18:02:20Z</updated>

		<summary type="html">&lt;p&gt;Bowersmt: Added more info on contains()&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[[MarkLogic|« Back to MarkLogic]]&lt;br /&gt;
&lt;br /&gt;
== Searching and Querying MarkLogic ==&lt;br /&gt;
Indexes are central to everything you do in MarkLogic.  They are central to how MarkLogic stores data, scales massively, and processes data quickly. They are central to how you develop because you have to use MarkLogic&#039;s indexes to query and search documents. You have to understand how MarkLogic&#039;s indexes work to be able to create fast queries. And you have to know how to model document structure to work best with indexes.&lt;br /&gt;
&lt;br /&gt;
=== How does MarkLogic compare to a relational database? ===&lt;br /&gt;
A document in MarkLogic is very much like a row in a relational database, and a document type ties documents together like a table ties rows together. MarkLogic collections group documents together, and this is a little bit like views in a relational database, which group together a filtered set of rows from one or more tables. A document in MarkLogic can have a flat structure like a relational table, or it can contain complex nestings of data.  Each nesting of data in a document represents another table in a relational database. For example, a single document in MarkLogic may represent many relational tables and its nested structure represents their one-to-one, many-to-one, and many-to-many relationships.  Both MarkLogic and relational databases use indexes to resolve queries without having to scan through rows or documents.&lt;br /&gt;
&lt;br /&gt;
Unlike relational databases, MarkLogic can&#039;t do full table scans; queries must use indexes. In contrast, relational databases often use a full table scan to retrieve every row in a table. A rule of thumb in relational databases is that it is faster to directly read in &#039;&#039;all&#039;&#039; the rows when a query accesses more than roughly 25% of the rows. This is because relational databases use variations of the B-Tree index, which requires 3-4 random IOs to find one row and 1 IO to retrieve the row: this is 4-5 total IOs per row.  B-Tree indexes work best for single row lookups, but they become increasingly costly the more rows they retrieve. If an index has to lookup 25% of its rows with 4 IOs per row, the database will do the same amount of IO if it reads in all of the rows (1 IO per row). Since sequential IO on disks is faster than random IO, relational databases prefer full table scans when accessing more than about 25% of rows in a table. On analytical data warehouses, full table scans are always preferred.  &lt;br /&gt;
&lt;br /&gt;
In addition, a relational database [https://docs.oracle.com/database/121/TGSQL/tgsql_optop.htm#TGSQL234 often directly scans through index data] rather than stepping through its B-Tree structure. Databases use a variety of index scans: full scans, range scans, skip scans, join scans, etc. This is index and table records are stored sequentially on disk. This often makes it faster to take advantage of the speed of sequential disk IO and directly load all index or table rows into RAM and process them in RAM; as opposed to walking a b-tree structure and doing multiple slow random IOs to retrieve each record. For the same reason, row and index scans work well in columnar NoSQL databases.&lt;br /&gt;
&lt;br /&gt;
=== Why do MarkLogic queries have to use Indexes? ===&lt;br /&gt;
To maximize parallelism and to spread processing throughout a cluster, MarkLogic spreads documents across the cluster. MarkLogic automatically creates multiple shards per server and spreads them across all the servers in the cluster. Documents are placed in a shard in the order they are created or modified; thus, documents of all types may be randomly intermixed in a shard. Since a shard is not organized by document type, doing a sequential scan to resolve a query would require retrieving and processing all documents in the database. Full scans are not practical in MarkLogic. All queries and searches need to use indexes. For this reason, MarkLogic automatically indexes almost everything. You can also create additional specialized indexes.  MarkLogic indexes are not B-Tree indexes; they are designed to be sharded and queried in parallel across stands, forests, and a database cluster that spans many servers.&lt;br /&gt;
&lt;br /&gt;
=== How does MarkLogic scale horizontally? ===&lt;br /&gt;
Documents in MarkLogic belong to a database. Within a database are one or more servers.  Each server may contain zero or more &amp;quot;forests&amp;quot;. Within each forest are one or more &amp;quot;stands&amp;quot;. Within each stand are one or more &amp;quot;trees&amp;quot;. A document is hierarchical so it is called a &amp;quot;tree&amp;quot;.  (MarkLogic uses the terms &amp;quot;stand&amp;quot; and &amp;quot;forest&amp;quot; instead of &amp;quot;shard&amp;quot;, but they have the same meaning.) &lt;br /&gt;
&lt;br /&gt;
A client contacts one of the servers in a MarkLogic cluster and initiates a query or search. Because MarkLogic communicates through REST web services, a load balancer can spread requests across the servers in a MarkLogic cluster.  The initiating server does the following&lt;br /&gt;
#it validates the query request from the client&lt;br /&gt;
#it parses and optimizes the query &lt;br /&gt;
#it sends the query to all servers that have forests in the database&lt;br /&gt;
##each server sends it to its forests &lt;br /&gt;
##each forest sends it to each stand &lt;br /&gt;
##each stand uses its indexes to find matching documents&lt;br /&gt;
###all stands and forests query the indexes in parallel&lt;br /&gt;
##forests combine the matching document IDs from all their stands&lt;br /&gt;
##forests sort the matching document IDs (in relevance score order or value order)&lt;br /&gt;
##when complete, each forest returns a sorted iterator to the initiating server&lt;br /&gt;
#when each forest has returned an iterator&lt;br /&gt;
#it walks the sorted iterators from all the forests and combines the results in sorted &lt;br /&gt;
#it retrieves matching documents from its &#039;&#039;Expanded Tree Cache&#039;&#039; or from the forests when documents are not cached&lt;br /&gt;
##forests retrieve documents from their &#039;&#039;Compressed Tree Cache&#039;&#039; or from disk when documents are not cached&lt;br /&gt;
#it filters returned documents to remove false positive matches &lt;br /&gt;
#it optionally transforms documents &lt;br /&gt;
##it creates new documents by extracting matching elements, changing structure, changing file format, etc.&lt;br /&gt;
#it returns all matching (optionally transformed) documents to the requester&lt;br /&gt;
#it saves resulting document IDs when paging query results, so it can return subsequent pages of matching documents in subsequent requests&lt;br /&gt;
&lt;br /&gt;
The initiating server&#039;s process is CPU intensive, serialized, and blocks while waiting on forests. To prevent this from being a bottleneck to the cluster, you can dedicate nodes in the cluster to do nothing but evaluate queries. These are called e-nodes (evaluation nodes). These nodes don&#039;t hold data. If they held data, the &#039;&#039;serialized&#039;&#039; evaluation process would compete with the &#039;&#039;parallel&#039;&#039; index matching process.  Instead e-nodes are dedicated to validating, parsing, sorting, filtering, transforming, and paginating documents. They cache documents in the &#039;&#039;Expanded Tree Cache&#039;&#039; to minimize the number of documents they have to retrieve from data nodes (d-nodes). D-nodes only do parallel index processing and sorting. They cache documents in their &#039;&#039;Compressed Tree Cache&#039;&#039; to reduce disk IO. &lt;br /&gt;
&lt;br /&gt;
=== How do you optimize a MarkLogic cluster to run queries faster? ===&lt;br /&gt;
*E-nodes and d-nodes can be scaled independently to match the load. &lt;br /&gt;
*You can optimize an e-node by minimizing its &#039;&#039;Compressed Tree Cache&#039;&#039; and maximizing its &#039;&#039;Expanded Tree Cache&#039;&#039;. An e-node needs a big &#039;&#039;Expanded Tree Cache&#039;&#039; so it doesn&#039;t have to retrieve as many documents from d-nodes. An e-node doesn&#039;t need a &#039;&#039;Compressed Tree Cache&#039;&#039; because it doesn&#039;t have any data.&lt;br /&gt;
*You can optimize a d-node by doing the opposite of the e-node: maximize the &#039;&#039;Compressed Tree Cache&#039;&#039; and minimize the &#039;&#039;Expanded Tree Cache&#039;&#039;. You can also optimize d-nodes by making sure each d-node runs on similar hardware and that each forest has a similar number of documents. This is important because all forests process queries in parallel and the slowest forest holds up each query: e-nodes have to wait until the slowest forest finishes.&lt;br /&gt;
*You can optimize a query by making it unfiltered.&lt;br /&gt;
**This means it is completely resolved by the indexes. Because no filtering is required, the initiating server doesn&#039;t have to verify that documents match.&lt;br /&gt;
*You can optimize a query by eliminating false positives.  &lt;br /&gt;
**False positives occur when a query identifies a possible match for a document, but it cannot prove it is a match until the filtering process opens the document and verifies it. &lt;br /&gt;
**False positives happen because MarkLogic only partially indexes certain document items. MarkLogic cannot index everything because it would take too much time and space. For example, MarkLogic has a structure index. It indexes relationships between elements in a document.  MarkLogic cannot afford to index each element&#039;s path from itself to every other element. MarkLogic compromises on indexing only parent/child relationships. This is effective in eliminating most non-matching documents, but it can produce false positives.  The only way to know if a document is an &#039;&#039;exact&#039;&#039; match, MarkLogic must open the document and verify it.&lt;br /&gt;
**For example, suppose a query searches for the following path: &amp;lt;br&amp;gt;&amp;lt;code&amp;gt;books/poetry/poem&amp;lt;/code&amp;gt;&amp;lt;br&amp;gt; The structure index will match documents containing books/poetry and poetry/poem. The resulting documents are a probable match, but could contain false positives, such as &amp;lt;br&amp;gt;&amp;lt;code&amp;gt;books/poetry/fantasy/poetry/poem&amp;lt;/code&amp;gt;.&lt;br /&gt;
**You can eliminate false positive structures queries by giving elements unique names. They are  unique no matter where in they are in the structure and they are more self-descriptive.  Instead of naming an element &amp;quot;line&amp;quot; which can mean many things, you can use the precise name  &amp;quot;poemTextLine&amp;quot;. &lt;br /&gt;
*You can optimize a query by greatly limiting how many documents it matches. Design each query to return as few documents as possible. &lt;br /&gt;
**It is expensive to transmit documents. Matching documents have to travel from stands to forests to the initiating server, and to the requester. &lt;br /&gt;
**It is expensive to process documents on the initiating server and the requester. &lt;br /&gt;
**It takes processing time on d-nodes to compare lists of document IDs. The fewer the matching document IDs in one part of the query, the faster the entire query runs. &lt;br /&gt;
**The more matching document IDs, the more work MarkLogic has to do in a d-node to compare, union, intersect, and subract them from matching document IDs returned by other parts of the query. &lt;br /&gt;
**The more matching document IDs, the more sorting MarkLogic has to do in the stands, forests, and initiating server.&lt;br /&gt;
&lt;br /&gt;
=== How does a MarkLogic query compare to map/reduce? ===&lt;br /&gt;
A MarkLogic query or search is similar to map/reduce.  When you query or search for documents in a database, MarkLogic spreads the work across all the servers to be executed in parallel. This is like a &#039;&#039;map&#039;&#039; process because indexes filter out non-matching documents by combining term, range, and semantic indexes according to the query map. The results are then &#039;&#039;reduced&#039;&#039; at the forest level and again at the database level and again at the initiating server. This parallel division of responsibilities enables MarkLogic to scale.&lt;br /&gt;
&lt;br /&gt;
== Term, Range, and Semantic Indexes ==&lt;br /&gt;
MarkLogic indexes are not B-Tree indexes. MarkLogic uses &#039;&#039;&#039;term&#039;&#039;&#039;, &#039;&#039;&#039;range&#039;&#039;&#039;, and &#039;&#039;&#039;semantic&#039;&#039;&#039; indexes. &lt;br /&gt;
*&#039;&#039;&#039;A term index&#039;&#039;&#039; associates a term with every document that contains the term.  For example, in a word index, every word in the database is stored in the index. Associated with each word in the index is a list of each document ID that contains the term.  &lt;br /&gt;
*&#039;&#039;&#039;A range index&#039;&#039;&#039; is a double term index: it contains each term and all document IDs that contain that term, and it contains each document ID and all the terms that are in the document.&lt;br /&gt;
*&#039;&#039;&#039;A semantic index&#039;&#039;&#039; is similar to a range index but it is optimized to store triples (three pieces of data: subject, object, and predicate).&lt;br /&gt;
&lt;br /&gt;
Term indexes are fast. Give the index a term, and with one lookup, it returns &#039;&#039;all&#039;&#039; documents that contain the term. Term indexes are memory mapped files. They run in RAM unless you run out of RAM and then firmware in the CPU efficiently swaps them to and from disk. Thus, it is best to have enough RAM in a MarkLogic server to contain all indexes in memory.&lt;br /&gt;
&lt;br /&gt;
Unlike B-Tree indexes, term indexes are easily sharded within and between servers. MarkLogic takes advantage of this to run queries in parallel within and across servers. This is how MarkLogic can scale to billions of documents and still return queries and searches in milliseconds.&lt;br /&gt;
&lt;br /&gt;
When documents are inserted or updated, MarkLogic indexes them in RAM (as well as appends the changes to a journal on disk). When documents in RAM start to consume too much RAM, MarkLogic writes them to disk as a &amp;quot;stand&amp;quot; in a &amp;quot;forest&amp;quot; and starts creating a new &amp;quot;stand&amp;quot; in RAM.  &lt;br /&gt;
&lt;br /&gt;
When you query or search for documents, MarkLogic goes to the indexes in the stands (which are cached in RAM) and evaluates the query in parallel. Each stand index returns a list of document IDs (a list of numbers) that match the query. MarkLogic takes the document IDs returned by each stand and merges them into a final list of document IDs, whcih it uses to retrieve the documents from cache or disk. This works well because computers are very fast at sort merging lists of numbers.&lt;br /&gt;
&lt;br /&gt;
MarkLogic uses the same indexes for both queries and searches. This allows you to combine search and query expressions. The main difference between search and query is how documents are sorted: searches sort by relevance and queries sort by values. Another difference is that queries tend to use value indexes and searches tend to use word and phrase indexes. &lt;br /&gt;
&lt;br /&gt;
=== What specific indexes does MarkLogic have? ===&lt;br /&gt;
MarkLogic uses indexes to extract words, values, structures, and links out of documents. An index is an altered view of a document. It enables you to search and query for documents &amp;lt;br&amp;gt;&#039;&#039;&#039;as if they contained only:&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
*&#039;&#039;&#039;Words:&#039;&#039;&#039; a flat set of words without structure, such as &amp;lt;br&amp;gt;&amp;lt;code&amp;gt;[&amp;quot;Mary&amp;quot;, &amp;quot;had&amp;quot;, &amp;quot;a&amp;quot;, &amp;quot;little&amp;quot;, &amp;quot;lamb&amp;quot;]&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
*&#039;&#039;&#039;Phrases:&#039;&#039;&#039; a flat set of phrases without structure, such as &amp;lt;br&amp;gt;&amp;lt;code&amp;gt;[&amp;quot;Mary had&amp;quot;, &amp;quot;had a&amp;quot;, &amp;quot;a little&amp;quot;, &amp;quot;little lamb&amp;quot;]&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
*&#039;&#039;&#039;Elements:&#039;&#039;&#039; a flat set of elements without values, such as &amp;lt;br&amp;gt;&amp;lt;code&amp;gt;[&amp;quot;poem&amp;quot;, &amp;quot;text&amp;quot;, &amp;quot;line&amp;quot;]&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
*&#039;&#039;&#039;Element-values:&#039;&#039;&#039; a flat set of elements with string values, such as &amp;lt;br&amp;gt;&amp;lt;code&amp;gt;&amp;quot;line&amp;quot;: &amp;quot;Mary had a little lamb&amp;quot;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
*&#039;&#039;&#039;Element-words:&#039;&#039;&#039; a flat set of elements with words, such as &amp;lt;br&amp;gt;&amp;lt;code&amp;gt;&amp;quot;line&amp;quot;: [&amp;quot;Mary&amp;quot;, &amp;quot;had&amp;quot;, &amp;quot;a&amp;quot;, &amp;quot;little&amp;quot;, &amp;quot;lamb&amp;quot;]&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
*&#039;&#039;&#039;Element-phrases:&#039;&#039;&#039; a flat set of elements with phrases, such as &amp;lt;br&amp;gt;&amp;lt;code&amp;gt;&amp;quot;line&amp;quot;: [&amp;quot;Mary had&amp;quot;, &amp;quot;had a&amp;quot;, &amp;quot;a little&amp;quot;, &amp;quot;little lamb&amp;quot;]&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
*&#039;&#039;&#039;Element-value lexicon:&#039;&#039;&#039; a flat set of elements with typed values, such as &amp;lt;br&amp;gt;&amp;lt;code&amp;gt;&amp;quot;lineSequence&amp;quot;: 3&amp;lt;/code&amp;gt;&amp;lt;br&amp;gt; or a list, count, or co-occurrence of element values scoped to a database, set of documents, or one document.&lt;br /&gt;
&lt;br /&gt;
*&#039;&#039;&#039;XPath-structure-value lexicon:&#039;&#039;&#039; a flat set of hierarchical elements with typed values, such as &amp;lt;br&amp;gt;&amp;lt;code&amp;gt;poem.text.line.lineSequence: 3&amp;lt;/code&amp;gt;&amp;lt;br&amp;gt; or a list, count, or co-occurrence of hierarchical element values scoped to a database, set of documents, or one document.&lt;br /&gt;
&lt;br /&gt;
*&#039;&#039;&#039;XPath-structure:&#039;&#039;&#039;hierarchical structures without values, such as &amp;lt;br&amp;gt;&amp;lt;code&amp;gt;poem.text.line&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
*&#039;&#039;&#039;XPath-structure-words:&#039;&#039;&#039; hierarchical structures with words, such as &amp;lt;br&amp;gt;&amp;lt;code&amp;gt;poem.text.line: [&amp;quot;Mary&amp;quot;, &amp;quot;had&amp;quot;, &amp;quot;a&amp;quot;, &amp;quot;little&amp;quot;, &amp;quot;lamb&amp;quot;]&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
*&#039;&#039;&#039;XPath-structure-phrases:&#039;&#039;&#039; hierarchical structures with phrases, such as &amp;lt;br&amp;gt;&amp;lt;code&amp;gt;poem.text.line: [&amp;quot;Mary had&amp;quot;, &amp;quot;had a&amp;quot;, &amp;quot;a little&amp;quot;, &amp;quot;little lamb&amp;quot;]&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
*&#039;&#039;&#039;XPath-structure-values:&#039;&#039;&#039; hierarchical structures with values, such as &amp;lt;br&amp;gt;&amp;lt;code&amp;gt;poem.text.line: &amp;quot;Mary had a little lamb&amp;quot;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
*&#039;&#039;&#039;RDF document links&#039;&#039;&#039; to other documents, such as &amp;lt;br&amp;gt;&amp;lt;code&amp;gt;{&amp;quot;subject&amp;quot;: &amp;quot;http://example.org/documents/thisDoc&amp;quot;, &amp;lt;br&amp;gt;&amp;quot;predicate&amp;quot;: &amp;quot;http://example.org/predicates/relatesSomehowTo&amp;quot;, &amp;lt;br&amp;gt;&amp;quot;object&amp;quot;: &amp;quot;http://example.org/documents/thatDoc&amp;quot;}&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
*&#039;&#039;&#039;RDF abstract links&#039;&#039;&#039; to other abstract concepts, such as &amp;lt;br&amp;gt;&amp;lt;code&amp;gt;{&amp;quot;subject&amp;quot;: &amp;quot;http://example.org/documents/thisDoc&amp;quot;, &amp;lt;br&amp;gt;&amp;quot;predicate&amp;quot;: &amp;quot;http://example.org/predicates/relatesSomehowTo&amp;quot;, &amp;lt;br&amp;gt;&amp;quot;object&amp;quot;: &amp;quot;http://example.org/documents/someConceptWithNoDocumentAtTheURI&amp;quot;}&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
*&#039;&#039;&#039;RDF data links&#039;&#039;&#039; to data, such as &amp;lt;br&amp;gt;&amp;lt;code&amp;gt;{&amp;quot;subject&amp;quot;: &amp;quot;http://example.org/documents/thisDoc&amp;quot;, &amp;lt;br&amp;gt;&amp;quot;predicate&amp;quot;: &amp;quot;http://example.org/predicates/ageInYears&amp;quot;, &amp;lt;br&amp;gt;&amp;quot;object&amp;quot;: 12}&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
MarkLogic can combine any of these indexes in any way to find matching documents.  It can sort the result by relevance or by value. &lt;br /&gt;
&lt;br /&gt;
Search and query expressions are fully composable; i.e. they can be nested inside each other and combined using AND, OR, and NOT expressions.&lt;br /&gt;
&lt;br /&gt;
== Search Functions in MarkLogic ==&lt;br /&gt;
=== Executing a Search ===&lt;br /&gt;
*&#039;&#039;&#039;&amp;lt;code&amp;gt;[http://docs.marklogic.com/cts:search cts:search]&amp;lt;/code&amp;gt;&#039;&#039;&#039; is the most important function because it executes a search and returns matching nodes. &lt;br /&gt;
**&#039;&#039;&#039;You must include an XPath expression&#039;&#039;&#039; to define which nodes to &#039;&#039;search&#039;&#039; and &#039;&#039;return&#039;&#039;. &lt;br /&gt;
**The search returns &#039;&#039;nodes&#039;&#039;, which can be documents, elements, attributes, or text. Thus, a search doesn&#039;t have to return entire documents. Depending on the scope of your XPath statement, it may return entire documents, or one matching node from each document, or many matching nodes from each document.  &lt;br /&gt;
**&#039;&#039;&#039;You must include a cts query expression&#039;&#039;&#039; to filter the contents of &#039;&#039;nodes&#039;&#039; selected by the XPath expression. This allows you to search for specific content within specific nodes and return only those nodes that contain that content. If you want to return all the nodes selected by the XPath expression, you can use the empty query expression: &amp;lt;code&amp;gt;cts:and-query(())&amp;lt;/code&amp;gt;.&lt;br /&gt;
**You may limit the search to specific forests. You may set options like unfiltered, faceted, unchecked, quality weight, relevance scoring method, and relevance trace.&lt;br /&gt;
**Use Cases:&lt;br /&gt;
***A search can return entire documents whose contents match the XPath and query expressions.&lt;br /&gt;
***A search can extract and return titles from documents as long as the contents of the titles match the XPath and query expressions.&lt;br /&gt;
***A search can extract and return all the paragraphs from documents as long as the contents of the paragraphs match the XPath and query expressions.&lt;br /&gt;
**Notes:&lt;br /&gt;
***There is no functional difference between searching entire documents and elements because an element has the same structure as document.  Both may contain complex nested elements or both may simply contain a value. In both cases, MarkLogic retrieves entire documents. In the case of elements, it extracts the requested elements from each retrieved document.&lt;br /&gt;
***Searching attributes, text nodes, and childless elements is similar to searching documents and elements with children — except the cts query cannot look for nested structures.&lt;br /&gt;
&lt;br /&gt;
*&#039;&#039;&#039;&amp;lt;code&amp;gt;[http://docs.marklogic.com/cts:contains cts:contains]&amp;lt;/code&amp;gt;&#039;&#039;&#039; is the second most important function because it returns true when a cts query finds at least one matching node in the nodes returned by an XPath expression (or a sequence of values). In other words, it returns true when at least one of the specified nodes &#039;&#039;&#039;contains&#039;&#039;&#039; the precise combination of words, phrases, values, structures, and/or triples in a cts query.&lt;br /&gt;
&lt;br /&gt;
=== Constructing a Query ===&lt;br /&gt;
You compose a query using cts query constructor functions. You then execute the query by passing it into &amp;lt;code&amp;gt;cts:search, cts:contains, search:search&amp;lt;/code&amp;gt;, and lexicon functions. MarkLogic has 30+ query constructors. They all end in &#039;&#039;&#039;&amp;quot;-query&amp;quot;&#039;&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
==== Composite Query Constructors ====&lt;br /&gt;
The composite query constructors build up new queries from other queries, and queries can be nested within queries.&lt;br /&gt;
&lt;br /&gt;
*&#039;&#039;&#039;&amp;lt;code&amp;gt;[http://docs.marklogic.com/cts:and-query cts:and-query]&amp;lt;/code&amp;gt;&#039;&#039;&#039; returns a query that intersects two or more sub-queries.&lt;br /&gt;
&lt;br /&gt;
*&#039;&#039;&#039;&amp;lt;code&amp;gt;[http://docs.marklogic.com/cts:or-query cts:or-query]&amp;lt;/code&amp;gt;&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
*&#039;&#039;&#039;&amp;lt;code&amp;gt;[http://docs.marklogic.com/cts:not-query cts:not-query]&amp;lt;/code&amp;gt;&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
*&#039;&#039;&#039;&amp;lt;code&amp;gt;[http://docs.marklogic.com/cts:and-not-query cts:and-not-query]&amp;lt;/code&amp;gt;&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
*&#039;&#039;&#039;&amp;lt;code&amp;gt;[http://docs.marklogic.com/cts:element-query cts:element-query]&amp;lt;/code&amp;gt;&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
*&#039;&#039;&#039;&amp;lt;code&amp;gt;[http://docs.marklogic.com/cts:document-fragment-query cts:document-fragment-query]&amp;lt;/code&amp;gt;&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
*&#039;&#039;&#039;&amp;lt;code&amp;gt;[http://docs.marklogic.com/cts:locks-query cts:locks-query]&amp;lt;/code&amp;gt;&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
*&#039;&#039;&#039;&amp;lt;code&amp;gt;[http://docs.marklogic.com/cts:properties-query cts:properties-query]&amp;lt;/code&amp;gt;&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
*&#039;&#039;&#039;&amp;lt;code&amp;gt;[http://docs.marklogic.com/cts:near-query cts:near-query]&amp;lt;/code&amp;gt;&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Training Resources for MarkLogic Search ==&lt;br /&gt;
* [http://developer.marklogic.com/blog/grokking-the-cts-api &amp;quot;Grokking the cts API&amp;quot;] is a great overview of MarkLogic&#039;s search and query capabilities.&lt;br /&gt;
&lt;br /&gt;
[[Category: MarkLogic]]&lt;/div&gt;</summary>
		<author><name>Bowersmt</name></author>
	</entry>
	<entry>
		<id>https://tech.churchofjesuschrist.org/wiki/index.php?title=MarkLogic_Query_and_Search&amp;diff=70570</id>
		<title>MarkLogic Query and Search</title>
		<link rel="alternate" type="text/html" href="https://tech.churchofjesuschrist.org/wiki/index.php?title=MarkLogic_Query_and_Search&amp;diff=70570"/>
		<updated>2014-11-15T07:12:09Z</updated>

		<summary type="html">&lt;p&gt;Bowersmt: Added some search functions&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[[MarkLogic|« Back to MarkLogic]]&lt;br /&gt;
&lt;br /&gt;
== Searching and Querying MarkLogic ==&lt;br /&gt;
Indexes are central to everything you do in MarkLogic.  They are central to how MarkLogic stores data, scales massively, and processes data quickly. They are central to how you develop because you have to use MarkLogic&#039;s indexes to query and search documents. You have to understand how MarkLogic&#039;s indexes work to be able to create fast queries. And you have to know how to model document structure to work best with indexes.&lt;br /&gt;
&lt;br /&gt;
=== How does MarkLogic compare to a relational database? ===&lt;br /&gt;
A document in MarkLogic is very much like a row in a relational database, and a document type ties documents together like a table ties rows together. Both use indexes to resolve queries without having to scan through rows or documents.&lt;br /&gt;
&lt;br /&gt;
Unlike relational databases, MarkLogic can&#039;t do full table scans; queries must use indexes. In contrast, relational databases often use a full table scan to retrieve every row in a table. A rule of thumb in relational databases is that it is faster to directly read in &#039;&#039;all&#039;&#039; the rows when a query accesses more than roughly 25% of the rows. This is because relational databases use variations of the B-Tree index, which requires 3-4 random IOs to find one row and 1 IO to retrieve the row: this is 4-5 total IOs per row.  B-Tree indexes work best for single row lookups, but they become increasingly costly the more rows they retrieve. If an index has to lookup 25% of its rows with 4 IOs per row, the database will do the same amount of IO if it reads in all of the rows (1 IO per row). Since sequential IO on disks is faster than random IO, relational databases prefer full table scans when accessing more than about 25% of rows in a table. On analytical data warehouses, full table scans are always preferred.  &lt;br /&gt;
&lt;br /&gt;
In addition, a relational database [https://docs.oracle.com/database/121/TGSQL/tgsql_optop.htm#TGSQL234 often directly scans through index data] rather than stepping through its B-Tree structure. Databases use a variety of index scans: full scans, range scans, skip scans, join scans, etc. This is index and table records are stored sequentially on disk. This often makes it faster to take advantage of the speed of sequential disk IO and directly load all index or table rows into RAM and process them in RAM; as opposed to walking a b-tree structure and doing multiple slow random IOs to retrieve each record. For the same reason, row and index scans work well in columnar NoSQL databases.&lt;br /&gt;
&lt;br /&gt;
=== Why do MarkLogic queries have to use Indexes? ===&lt;br /&gt;
To maximize parallelism and to spread processing throughout a cluster, MarkLogic spreads documents across the cluster. MarkLogic automatically creates multiple shards per server and spreads them across all the servers in the cluster. Documents are placed in a shard in the order they are created or modified; thus, documents of all types may be randomly intermixed in a shard. Since a shard is not organized by document type, doing a sequential scan to resolve a query would require retrieving and processing all documents in the database. Full scans are not practical in MarkLogic. All queries and searches need to use indexes. For this reason, MarkLogic automatically indexes almost everything. You can also create additional specialized indexes.  MarkLogic indexes are not B-Tree indexes; they are designed to be sharded and queried in parallel across stands, forests, and a database cluster that spans many servers.&lt;br /&gt;
&lt;br /&gt;
=== How does MarkLogic scale horizontally? ===&lt;br /&gt;
Documents in MarkLogic belong to a database. Within a database are one or more servers.  Each server may contain zero or more &amp;quot;forests&amp;quot;. Within each forest are one or more &amp;quot;stands&amp;quot;. Within each stand are one or more &amp;quot;trees&amp;quot;. A document is hierarchical so it is called a &amp;quot;tree&amp;quot;.  (MarkLogic uses the terms &amp;quot;stand&amp;quot; and &amp;quot;forest&amp;quot; instead of &amp;quot;shard&amp;quot;, but they have the same meaning.) &lt;br /&gt;
&lt;br /&gt;
A client contacts one of the servers in a MarkLogic cluster and initiates a query or search. Because MarkLogic communicates through REST web services, a load balancer can spread requests across the servers in a MarkLogic cluster.  The initiating server does the following&lt;br /&gt;
#it validates the query request from the client&lt;br /&gt;
#it parses and optimizes the query &lt;br /&gt;
#it sends the query to all servers that have forests in the database&lt;br /&gt;
##each server sends it to its forests &lt;br /&gt;
##each forest sends it to each stand &lt;br /&gt;
##each stand uses its indexes to find matching documents&lt;br /&gt;
###all stands and forests query the indexes in parallel&lt;br /&gt;
##forests combine the matching document IDs from all their stands&lt;br /&gt;
##forests sort the matching document IDs (in relevance score order or value order)&lt;br /&gt;
##when complete, each forest returns a sorted iterator to the initiating server&lt;br /&gt;
#when each forest has returned an iterator&lt;br /&gt;
#it walks the sorted iterators from all the forests and combines the results in sorted &lt;br /&gt;
#it retrieves matching documents from its &#039;&#039;Expanded Tree Cache&#039;&#039; or from the forests when documents are not cached&lt;br /&gt;
##forests retrieve documents from their &#039;&#039;Compressed Tree Cache&#039;&#039; or from disk when documents are not cached&lt;br /&gt;
#it filters returned documents to remove false positive matches &lt;br /&gt;
#it optionally transforms documents &lt;br /&gt;
##it creates new documents by extracting matching elements, changing structure, changing file format, etc.&lt;br /&gt;
#it returns all matching (optionally transformed) documents to the requester&lt;br /&gt;
#it saves resulting document IDs when paging query results, so it can return subsequent pages of matching documents in subsequent requests&lt;br /&gt;
&lt;br /&gt;
The initiating server&#039;s process is CPU intensive, serialized, and blocks while waiting on forests. To prevent this from being a bottleneck to the cluster, you can dedicate nodes in the cluster to do nothing but evaluate queries. These are called e-nodes (evaluation nodes). These nodes don&#039;t hold data. If they held data, the &#039;&#039;serialized&#039;&#039; evaluation process would compete with the &#039;&#039;parallel&#039;&#039; index matching process.  Instead e-nodes are dedicated to validating, parsing, sorting, filtering, transforming, and paginating documents. They cache documents in the &#039;&#039;Expanded Tree Cache&#039;&#039; to minimize the number of documents they have to retrieve from data nodes (d-nodes). D-nodes only do parallel index processing and sorting. They cache documents in their &#039;&#039;Compressed Tree Cache&#039;&#039; to reduce disk IO. &lt;br /&gt;
&lt;br /&gt;
=== How do you optimize a MarkLogic cluster to run queries faster? ===&lt;br /&gt;
*E-nodes and d-nodes can be scaled independently to match the load. &lt;br /&gt;
*You can optimize an e-node by minimizing its &#039;&#039;Compressed Tree Cache&#039;&#039; and maximizing its &#039;&#039;Expanded Tree Cache&#039;&#039;. An e-node needs a big &#039;&#039;Expanded Tree Cache&#039;&#039; so it doesn&#039;t have to retrieve as many documents from d-nodes. An e-node doesn&#039;t need a &#039;&#039;Compressed Tree Cache&#039;&#039; because it doesn&#039;t have any data.&lt;br /&gt;
*You can optimize a d-node by doing the opposite of the e-node: maximize the &#039;&#039;Compressed Tree Cache&#039;&#039; and minimize the &#039;&#039;Expanded Tree Cache&#039;&#039;. You can also optimize d-nodes by making sure each d-node runs on similar hardware and that each forest has a similar number of documents. This is important because all forests process queries in parallel and the slowest forest holds up each query: e-nodes have to wait until the slowest forest finishes.&lt;br /&gt;
*You can optimize a query by making it unfiltered.&lt;br /&gt;
**This means it is completely resolved by the indexes. Because no filtering is required, the initiating server doesn&#039;t have to verify that documents match.&lt;br /&gt;
*You can optimize a query by eliminating false positives.  &lt;br /&gt;
**False positives occur when a query identifies a possible match for a document, but it cannot prove it is a match until the filtering process opens the document and verifies it. &lt;br /&gt;
**False positives happen because MarkLogic only partially indexes certain document items. MarkLogic cannot index everything because it would take too much time and space. For example, MarkLogic has a structure index. It indexes relationships between elements in a document.  MarkLogic cannot afford to index each element&#039;s path from itself to every other element. MarkLogic compromises on indexing only parent/child relationships. This is effective in eliminating most non-matching documents, but it can produce false positives.  The only way to know if a document is an &#039;&#039;exact&#039;&#039; match, MarkLogic must open the document and verify it.&lt;br /&gt;
**For example, suppose a query searches for the following path: &amp;lt;br&amp;gt;&amp;lt;code&amp;gt;books/poetry/poem&amp;lt;/code&amp;gt;&amp;lt;br&amp;gt; The structure index will match documents containing books/poetry and poetry/poem. The resulting documents are a probable match, but could contain false positives, such as &amp;lt;br&amp;gt;&amp;lt;code&amp;gt;books/poetry/fantasy/poetry/poem&amp;lt;/code&amp;gt;.&lt;br /&gt;
**You can eliminate false positive structures queries by giving elements unique names. They are  unique no matter where in they are in the structure and they are more self-descriptive.  Instead of naming an element &amp;quot;line&amp;quot; which can mean many things, you can use the precise name  &amp;quot;poemTextLine&amp;quot;. &lt;br /&gt;
*You can optimize a query by greatly limiting how many documents it matches. Design each query to return as few documents as possible. &lt;br /&gt;
**It is expensive to transmit documents. Matching documents have to travel from stands to forests to the initiating server, and to the requester. &lt;br /&gt;
**It is expensive to process documents on the initiating server and the requester. &lt;br /&gt;
**It takes processing time on d-nodes to compare lists of document IDs. The fewer the matching document IDs in one part of the query, the faster the entire query runs. &lt;br /&gt;
**The more matching document IDs, the more work MarkLogic has to do in a d-node to compare, union, intersect, and subract them from matching document IDs returned by other parts of the query. &lt;br /&gt;
**The more matching document IDs, the more sorting MarkLogic has to do in the stands, forests, and initiating server.&lt;br /&gt;
&lt;br /&gt;
=== How does a MarkLogic query compare to map/reduce? ===&lt;br /&gt;
A MarkLogic query or search is similar to map/reduce.  When you query or search for documents in a database, MarkLogic spreads the work across all the servers to be executed in parallel. This is like a &#039;&#039;map&#039;&#039; process because indexes filter out non-matching documents by combining term, range, and semantic indexes according to the query map. The results are then &#039;&#039;reduced&#039;&#039; at the forest level and again at the database level and again at the initiating server. This parallel division of responsibilities enables MarkLogic to scale.&lt;br /&gt;
&lt;br /&gt;
== Term, Range, and Semantic Indexes ==&lt;br /&gt;
MarkLogic indexes are not B-Tree indexes. MarkLogic uses &#039;&#039;&#039;term&#039;&#039;&#039;, &#039;&#039;&#039;range&#039;&#039;&#039;, and &#039;&#039;&#039;semantic&#039;&#039;&#039; indexes. &lt;br /&gt;
*&#039;&#039;&#039;A term index&#039;&#039;&#039; associates a term with every document that contains the term.  For example, in a word index, every word in the database is stored in the index. Associated with each word in the index is a list of each document ID that contains the term.  &lt;br /&gt;
*&#039;&#039;&#039;A range index&#039;&#039;&#039; is a double term index: it contains each term and all document IDs that contain that term, and it contains each document ID and all the terms that are in the document.&lt;br /&gt;
*&#039;&#039;&#039;A semantic index&#039;&#039;&#039; is similar to a range index but it is optimized to store triples (three pieces of data: subject, object, and predicate).&lt;br /&gt;
&lt;br /&gt;
Term indexes are fast. Give the index a term, and with one lookup, it returns &#039;&#039;all&#039;&#039; documents that contain the term. Term indexes are memory mapped files. They run in RAM unless you run out of RAM and then firmware in the CPU efficiently swaps them to and from disk. Thus, it is best to have enough RAM in a MarkLogic server to contain all indexes in memory.&lt;br /&gt;
&lt;br /&gt;
Unlike B-Tree indexes, term indexes are easily sharded within and between servers. MarkLogic takes advantage of this to run queries in parallel within and across servers. This is how MarkLogic can scale to billions of documents and still return queries and searches in milliseconds.&lt;br /&gt;
&lt;br /&gt;
When documents are inserted or updated, MarkLogic indexes them in RAM (as well as appends the changes to a journal on disk). When documents in RAM start to consume too much RAM, MarkLogic writes them to disk as a &amp;quot;stand&amp;quot; in a &amp;quot;forest&amp;quot; and starts creating a new &amp;quot;stand&amp;quot; in RAM.  &lt;br /&gt;
&lt;br /&gt;
When you query or search for documents, MarkLogic goes to the indexes in the stands (which are cached in RAM) and evaluates the query in parallel. Each stand index returns a list of document IDs (a list of numbers) that match the query. MarkLogic takes the document IDs returned by each stand and merges them into a final list of document IDs, whcih it uses to retrieve the documents from cache or disk. This works well because computers are very fast at sort merging lists of numbers.&lt;br /&gt;
&lt;br /&gt;
MarkLogic uses the same indexes for both queries and searches. This allows you to combine search and query expressions. The main difference between search and query is how documents are sorted: searches sort by relevance and queries sort by values. Another difference is that queries tend to use value indexes and searches tend to use word and phrase indexes. &lt;br /&gt;
&lt;br /&gt;
=== What specific indexes does MarkLogic have? ===&lt;br /&gt;
MarkLogic uses indexes to extract words, values, structures, and links out of documents. An index is an altered view of a document. It enables you to search and query for documents &amp;lt;br&amp;gt;&#039;&#039;&#039;as if they contained only:&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
*&#039;&#039;&#039;Words:&#039;&#039;&#039; a flat set of words without structure, such as &amp;lt;br&amp;gt;&amp;lt;code&amp;gt;[&amp;quot;Mary&amp;quot;, &amp;quot;had&amp;quot;, &amp;quot;a&amp;quot;, &amp;quot;little&amp;quot;, &amp;quot;lamb&amp;quot;]&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
*&#039;&#039;&#039;Phrases:&#039;&#039;&#039; a flat set of phrases without structure, such as &amp;lt;br&amp;gt;&amp;lt;code&amp;gt;[&amp;quot;Mary had&amp;quot;, &amp;quot;had a&amp;quot;, &amp;quot;a little&amp;quot;, &amp;quot;little lamb&amp;quot;]&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
*&#039;&#039;&#039;Elements:&#039;&#039;&#039; a flat set of elements without values, such as &amp;lt;br&amp;gt;&amp;lt;code&amp;gt;[&amp;quot;poem&amp;quot;, &amp;quot;text&amp;quot;, &amp;quot;line&amp;quot;]&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
*&#039;&#039;&#039;Element-values:&#039;&#039;&#039; a flat set of elements with string values, such as &amp;lt;br&amp;gt;&amp;lt;code&amp;gt;&amp;quot;line&amp;quot;: &amp;quot;Mary had a little lamb&amp;quot;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
*&#039;&#039;&#039;Element-words:&#039;&#039;&#039; a flat set of elements with words, such as &amp;lt;br&amp;gt;&amp;lt;code&amp;gt;&amp;quot;line&amp;quot;: [&amp;quot;Mary&amp;quot;, &amp;quot;had&amp;quot;, &amp;quot;a&amp;quot;, &amp;quot;little&amp;quot;, &amp;quot;lamb&amp;quot;]&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
*&#039;&#039;&#039;Element-phrases:&#039;&#039;&#039; a flat set of elements with phrases, such as &amp;lt;br&amp;gt;&amp;lt;code&amp;gt;&amp;quot;line&amp;quot;: [&amp;quot;Mary had&amp;quot;, &amp;quot;had a&amp;quot;, &amp;quot;a little&amp;quot;, &amp;quot;little lamb&amp;quot;]&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
*&#039;&#039;&#039;Element-value lexicon:&#039;&#039;&#039; a flat set of elements with typed values, such as &amp;lt;br&amp;gt;&amp;lt;code&amp;gt;&amp;quot;lineSequence&amp;quot;: 3&amp;lt;/code&amp;gt;&amp;lt;br&amp;gt; or a list, count, or co-occurrence of element values scoped to a database, set of documents, or one document.&lt;br /&gt;
&lt;br /&gt;
*&#039;&#039;&#039;XPath-structure-value lexicon:&#039;&#039;&#039; a flat set of hierarchical elements with typed values, such as &amp;lt;br&amp;gt;&amp;lt;code&amp;gt;poem.text.line.lineSequence: 3&amp;lt;/code&amp;gt;&amp;lt;br&amp;gt; or a list, count, or co-occurrence of hierarchical element values scoped to a database, set of documents, or one document.&lt;br /&gt;
&lt;br /&gt;
*&#039;&#039;&#039;XPath-structure:&#039;&#039;&#039;hierarchical structures without values, such as &amp;lt;br&amp;gt;&amp;lt;code&amp;gt;poem.text.line&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
*&#039;&#039;&#039;XPath-structure-words:&#039;&#039;&#039; hierarchical structures with words, such as &amp;lt;br&amp;gt;&amp;lt;code&amp;gt;poem.text.line: [&amp;quot;Mary&amp;quot;, &amp;quot;had&amp;quot;, &amp;quot;a&amp;quot;, &amp;quot;little&amp;quot;, &amp;quot;lamb&amp;quot;]&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
*&#039;&#039;&#039;XPath-structure-phrases:&#039;&#039;&#039; hierarchical structures with phrases, such as &amp;lt;br&amp;gt;&amp;lt;code&amp;gt;poem.text.line: [&amp;quot;Mary had&amp;quot;, &amp;quot;had a&amp;quot;, &amp;quot;a little&amp;quot;, &amp;quot;little lamb&amp;quot;]&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
*&#039;&#039;&#039;XPath-structure-values:&#039;&#039;&#039; hierarchical structures with values, such as &amp;lt;br&amp;gt;&amp;lt;code&amp;gt;poem.text.line: &amp;quot;Mary had a little lamb&amp;quot;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
*&#039;&#039;&#039;RDF document links&#039;&#039;&#039; to other documents, such as &amp;lt;br&amp;gt;&amp;lt;code&amp;gt;{&amp;quot;subject&amp;quot;: &amp;quot;http://example.org/documents/thisDoc&amp;quot;, &amp;lt;br&amp;gt;&amp;quot;predicate&amp;quot;: &amp;quot;http://example.org/predicates/relatesSomehowTo&amp;quot;, &amp;lt;br&amp;gt;&amp;quot;object&amp;quot;: &amp;quot;http://example.org/documents/thatDoc&amp;quot;}&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
*&#039;&#039;&#039;RDF abstract links&#039;&#039;&#039; to other abstract concepts, such as &amp;lt;br&amp;gt;&amp;lt;code&amp;gt;{&amp;quot;subject&amp;quot;: &amp;quot;http://example.org/documents/thisDoc&amp;quot;, &amp;lt;br&amp;gt;&amp;quot;predicate&amp;quot;: &amp;quot;http://example.org/predicates/relatesSomehowTo&amp;quot;, &amp;lt;br&amp;gt;&amp;quot;object&amp;quot;: &amp;quot;http://example.org/documents/someConceptWithNoDocumentAtTheURI&amp;quot;}&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
*&#039;&#039;&#039;RDF data links&#039;&#039;&#039; to data, such as &amp;lt;br&amp;gt;&amp;lt;code&amp;gt;{&amp;quot;subject&amp;quot;: &amp;quot;http://example.org/documents/thisDoc&amp;quot;, &amp;lt;br&amp;gt;&amp;quot;predicate&amp;quot;: &amp;quot;http://example.org/predicates/ageInYears&amp;quot;, &amp;lt;br&amp;gt;&amp;quot;object&amp;quot;: 12}&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
MarkLogic can combine any of these indexes in any way to find matching documents.  It can sort the result by relevance or by value. &lt;br /&gt;
&lt;br /&gt;
Search and query expressions are fully composable; i.e. they can be nested inside each other and combined using AND, OR, and NOT expressions.&lt;br /&gt;
&lt;br /&gt;
== Search Functions in MarkLogic ==&lt;br /&gt;
=== Executing a Search ===&lt;br /&gt;
*&#039;&#039;&#039;&amp;lt;code&amp;gt;[http://docs.marklogic.com/cts:search cts:search]&amp;lt;/code&amp;gt;&#039;&#039;&#039; is the most important function because it executes a search and returns matching nodes. &lt;br /&gt;
**&#039;&#039;&#039;You must include an XPath expression&#039;&#039;&#039; to define which nodes to &#039;&#039;search&#039;&#039; and &#039;&#039;return&#039;&#039;. &lt;br /&gt;
**The search returns &#039;&#039;nodes&#039;&#039;, which can be documents, elements, attributes, text, processing instructions, comments, and namespaces. Thus, a search doesn&#039;t have to return entire documents. Depending on the scope of your XPath statement, it may return entire documents, or one matching node from each document, or many matching nodes from each document.  &lt;br /&gt;
**&#039;&#039;&#039;You must include a cts query expression&#039;&#039;&#039; to filter the contents of &#039;&#039;nodes&#039;&#039; selected by the XPath expression. This allows you to search for specific content within specific nodes and return only those nodes that contain that content. If you want to return all the nodes selected by the XPath expression, you can use the empty query expression: &amp;lt;code&amp;gt;cts:and-query(())&amp;lt;/code&amp;gt;.&lt;br /&gt;
**You may limit the search to specific forests. You may set options like unfiltered, faceted, unchecked, quality weight, relevance scoring method, and relevance trace.&lt;br /&gt;
**Use Cases:&lt;br /&gt;
***A search can return entire documents whose contents match the XPath and query expressions.&lt;br /&gt;
***A search can extract and return titles from documents as long as the contents of the titles match the XPath and query expressions.&lt;br /&gt;
***A search can extract and return all the paragraphs from documents as long as the contents of the paragraphs match the XPath and query expressions.&lt;br /&gt;
&lt;br /&gt;
*&#039;&#039;&#039;&amp;lt;code&amp;gt;[http://docs.marklogic.com/cts:contains cts:contains]&amp;lt;/code&amp;gt;&#039;&#039;&#039; is the second most important function because it returns true when any of a sequence of documents or values contains words, phrases, values, structures or triples specified by a cts query.&lt;br /&gt;
&lt;br /&gt;
=== Constructing a Query ===&lt;br /&gt;
You compose a query using cts query constructor functions. You then execute the query by passing it into &amp;lt;code&amp;gt;cts:search, cts:contains, search:search&amp;lt;/code&amp;gt;, and lexicon functions. MarkLogic has 30+ query constructors. They all end in &#039;&#039;&#039;&amp;quot;-query&amp;quot;&#039;&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
==== Composite Query Constructors ====&lt;br /&gt;
The composite query constructors build up new queries from other queries, and queries can be nested within queries.&lt;br /&gt;
&lt;br /&gt;
*&#039;&#039;&#039;&amp;lt;code&amp;gt;[http://docs.marklogic.com/cts:and-query cts:and-query]&amp;lt;/code&amp;gt;&#039;&#039;&#039; returns a query that intersects two or more sub-queries.&lt;br /&gt;
&lt;br /&gt;
*&#039;&#039;&#039;&amp;lt;code&amp;gt;[http://docs.marklogic.com/cts:or-query cts:or-query]&amp;lt;/code&amp;gt;&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
*&#039;&#039;&#039;&amp;lt;code&amp;gt;[http://docs.marklogic.com/cts:not-query cts:not-query]&amp;lt;/code&amp;gt;&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
*&#039;&#039;&#039;&amp;lt;code&amp;gt;[http://docs.marklogic.com/cts:and-not-query cts:and-not-query]&amp;lt;/code&amp;gt;&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
*&#039;&#039;&#039;&amp;lt;code&amp;gt;[http://docs.marklogic.com/cts:element-query cts:element-query]&amp;lt;/code&amp;gt;&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
*&#039;&#039;&#039;&amp;lt;code&amp;gt;[http://docs.marklogic.com/cts:document-fragment-query cts:document-fragment-query]&amp;lt;/code&amp;gt;&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
*&#039;&#039;&#039;&amp;lt;code&amp;gt;[http://docs.marklogic.com/cts:locks-query cts:locks-query]&amp;lt;/code&amp;gt;&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
*&#039;&#039;&#039;&amp;lt;code&amp;gt;[http://docs.marklogic.com/cts:properties-query cts:properties-query]&amp;lt;/code&amp;gt;&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
*&#039;&#039;&#039;&amp;lt;code&amp;gt;[http://docs.marklogic.com/cts:near-query cts:near-query]&amp;lt;/code&amp;gt;&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Training Resources for MarkLogic Search ==&lt;br /&gt;
* [http://developer.marklogic.com/blog/grokking-the-cts-api &amp;quot;Grokking the cts API&amp;quot;] is a great overview of MarkLogic&#039;s search and query capabilities.&lt;br /&gt;
&lt;br /&gt;
[[Category: MarkLogic]]&lt;/div&gt;</summary>
		<author><name>Bowersmt</name></author>
	</entry>
	<entry>
		<id>https://tech.churchofjesuschrist.org/wiki/index.php?title=Installing_MarkLogic&amp;diff=70569</id>
		<title>Installing MarkLogic</title>
		<link rel="alternate" type="text/html" href="https://tech.churchofjesuschrist.org/wiki/index.php?title=Installing_MarkLogic&amp;diff=70569"/>
		<updated>2014-11-14T08:55:27Z</updated>

		<summary type="html">&lt;p&gt;Bowersmt: Added back to MarkLogic&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[[MarkLogic|« Back to MarkLogic]]&lt;br /&gt;
&lt;br /&gt;
== Installing MarkLogic on Windows ==&lt;br /&gt;
(These instructions are for Windows XP, Vista, and 7. Installation and server start-up may differ slightly for other operating systems.)&lt;br /&gt;
&lt;br /&gt;
# [http://developer.marklogic.com/products Download] the latest version of the MarkLogic Server for your operating system.&lt;br /&gt;
#* Upon clicking on the download link, you will need to agree to MarkLogic&#039;s Terms of Use.&lt;br /&gt;
# Execute the MarkLogic Server installer.&lt;br /&gt;
#* Choose a &amp;quot;Typical&amp;quot; setup. This will take about 5 minutes.&lt;br /&gt;
# After installation is complete start the Mark Logic Server.&lt;br /&gt;
#* (Windows Only) Go to Start &amp;gt; All Programs &amp;gt; MarkLogic Server &amp;gt; Start MarkLogic Server&lt;br /&gt;
#** Important! Right-click on &amp;quot;Start MarkLogic Server&amp;quot; and select &amp;quot;Run as administrator&amp;quot;. Otherwise, the server may not start.&lt;br /&gt;
#** If you get the error message &amp;quot;The application failed to initialize properly...&amp;quot;, then see [http://developer.marklogic.com/products/marklogic-server/requirements MarkLogic Server 4.x System Requirements] to download and install the necessary dll for your operating system. Then try starting the server again.&lt;br /&gt;
#** If start-up succeeds, you will not see any message.&lt;br /&gt;
# Go to the Mark Logic administration console:&lt;br /&gt;
#* (Windows Only) Go to Start &amp;gt; All Program &amp;gt; MarkLogic Server &amp;gt; Admin MarkLogic Server.&lt;br /&gt;
#* A browser window will open and you will be prompted to enter a license key.&lt;br /&gt;
#** If you do not yet have a license, do one of the following:&lt;br /&gt;
#*** (Employees Only) Request a license key by emailing [mailto:DL-ICS-MARKLOGIC DL-ICS-MARKLOGIC].&lt;br /&gt;
#**** Enter the licensee and the license key, then click &amp;quot;OK&amp;quot;. The MarkLogic Server will restart.&lt;br /&gt;
#*** (Non-employees Only) You may request a free license for community development by clicking the &amp;quot;Free&amp;quot; button and then entering the required information in the supplied form.&lt;br /&gt;
#**** &#039;&#039;&#039;Licensee&#039;&#039;&#039;. This is &#039;&#039;&#039;your&#039;&#039;&#039; name.&lt;br /&gt;
#**** &#039;&#039;&#039;Company&#039;&#039;&#039;. &#039;&#039;Do NOT put the name of the Church or any of its business entities in this field.&#039;&#039; You may put &amp;quot;Home&amp;quot; or &amp;quot;Community&amp;quot; in this field if you will be using the MarkLogic Server for personal or community development.&lt;br /&gt;
#**** &#039;&#039;&#039;Email&#039;&#039;&#039;. This is your personal email address.&lt;br /&gt;
#**** Choose &amp;quot;Select Community License&amp;quot;.&lt;br /&gt;
#**** Make a copy of your license information and then click &amp;quot;OK&amp;quot;. The MarkLogic Server will restart.&lt;br /&gt;
#* Accept the license agreement by scrolling to the bottom of the page and clicking &amp;quot;Accept&amp;quot;. The MarkLogic Server will restart.&lt;br /&gt;
#* You will now be prompted to install the initial databases and application servers. Click &amp;quot;OK&amp;quot; to continue. When installation is complete. The server will restart.&lt;br /&gt;
#* When prompted to enter an Admin username and password, enter &amp;quot;admin&amp;quot; as the user and &amp;quot;admin&amp;quot; as the password. Confirm the password and click &amp;quot;OK&amp;quot; to continue.&lt;br /&gt;
#* When prompted, enter the user name and password you supplied. You will then be redirected to the MarkLogic Server administration console.&lt;br /&gt;
# Configure an XDBC server&lt;br /&gt;
#* Expand &amp;quot;Groups&amp;quot;, then expand &amp;quot;Default&amp;quot;, and then select &amp;quot;App Servers&amp;quot;.&lt;br /&gt;
#*; &amp;lt;br/&amp;gt;[[File:marklogic-admin-step1.png]]&amp;lt;br/&amp;gt;&amp;lt;br/&amp;gt;&lt;br /&gt;
#* Click the tab &amp;quot;Create XDBC&amp;quot;&lt;br /&gt;
#** Supply an XDBC server name.&lt;br /&gt;
#*** For the Stack Petstore project, enter &amp;quot;stack-petstore&amp;quot;.&lt;br /&gt;
#** Supply a value for the module directory root.&lt;br /&gt;
#*** For the Stack Petstore project, enter &amp;quot;/&amp;quot;.&lt;br /&gt;
#** Supply a value for the port the XDBC server will listen to for connections.&lt;br /&gt;
#*** For the Stack Petstore project, enter &amp;quot;8010&amp;quot;.&lt;br /&gt;
#** For the modules field, choose &amp;quot;Modules&amp;quot; from the list of options.&lt;br /&gt;
#** Leave all other fields as they are, and click &amp;quot;OK&amp;quot; at the top of the page.&lt;br /&gt;
#*; &amp;lt;br/&amp;gt;[[File:marklogic-admin-step2.png]]&amp;lt;br/&amp;gt;&amp;lt;br/&amp;gt;&lt;br /&gt;
# To try out your Mark Logic installation, go to [http://localhost:8000 &amp;lt;nowiki&amp;gt;http://localhost:8000&amp;lt;/nowiki&amp;gt;] and login with your admin username.&lt;br /&gt;
&lt;br /&gt;
[[Category:MarkLogic]]&lt;/div&gt;</summary>
		<author><name>Bowersmt</name></author>
	</entry>
	<entry>
		<id>https://tech.churchofjesuschrist.org/wiki/index.php?title=MarkLogic_Query_and_Search&amp;diff=70568</id>
		<title>MarkLogic Query and Search</title>
		<link rel="alternate" type="text/html" href="https://tech.churchofjesuschrist.org/wiki/index.php?title=MarkLogic_Query_and_Search&amp;diff=70568"/>
		<updated>2014-11-14T08:54:41Z</updated>

		<summary type="html">&lt;p&gt;Bowersmt: Added Back to MarkLogic&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[[MarkLogic|« Back to MarkLogic]]&lt;br /&gt;
&lt;br /&gt;
== Searching and Querying MarkLogic ==&lt;br /&gt;
Indexes are central to everything you do in MarkLogic.  They are central to how MarkLogic stores data, scales massively, and processes data quickly. They are central to how you develop because you have to use MarkLogic&#039;s indexes to query and search documents. You have to understand how MarkLogic&#039;s indexes work to be able to create fast queries. And you have to know how to model document structure to work best with indexes.&lt;br /&gt;
&lt;br /&gt;
=== How does MarkLogic compare to a relational database? ===&lt;br /&gt;
A document in MarkLogic is very much like a row in a relational database, and a document type ties documents together like a table ties rows together. Both use indexes to resolve queries without having to scan through rows or documents.&lt;br /&gt;
&lt;br /&gt;
Unlike relational databases, MarkLogic can&#039;t do full table scans; queries must use indexes. In contrast, relational databases often use a full table scan to retrieve every row in a table. A rule of thumb in relational databases is that it is faster to directly read in &#039;&#039;all&#039;&#039; the rows when a query accesses more than roughly 25% of the rows. This is because relational databases use variations of the B-Tree index, which requires 3-4 random IOs to find one row and 1 IO to retrieve the row: this is 4-5 total IOs per row.  B-Tree indexes work best for single row lookups, but they become increasingly costly the more rows they retrieve. If an index has to lookup 25% of its rows with 4 IOs per row, the database will do the same amount of IO if it reads in all of the rows (1 IO per row). Since sequential IO on disks is faster than random IO, relational databases prefer full table scans when accessing more than about 25% of rows in a table. On analytical data warehouses, full table scans are always preferred.  &lt;br /&gt;
&lt;br /&gt;
In addition, a relational database [https://docs.oracle.com/database/121/TGSQL/tgsql_optop.htm#TGSQL234 often directly scans through index data] rather than stepping through its B-Tree structure. Databases use a variety of index scans: full scans, range scans, skip scans, join scans, etc. This is index and table records are stored sequentially on disk. This often makes it faster to take advantage of the speed of sequential disk IO and directly load all index or table rows into RAM and process them in RAM; as opposed to walking a b-tree structure and doing multiple slow random IOs to retrieve each record. For the same reason, row and index scans work well in columnar NoSQL databases.&lt;br /&gt;
&lt;br /&gt;
=== Why do MarkLogic queries have to use Indexes? ===&lt;br /&gt;
To maximize parallelism and to spread processing throughout a cluster, MarkLogic spreads documents across the cluster. MarkLogic automatically creates multiple shards per server and spreads them across all the servers in the cluster. Documents are placed in a shard in the order they are created or modified; thus, documents of all types may be randomly intermixed in a shard. Since a shard is not organized by document type, doing a sequential scan to resolve a query would require retrieving and processing all documents in the database. Full scans are not practical in MarkLogic. All queries and searches need to use indexes. For this reason, MarkLogic automatically indexes almost everything. You can also create additional specialized indexes.  MarkLogic indexes are not B-Tree indexes; they are designed to be sharded and queried in parallel across stands, forests, and a database cluster that spans many servers.&lt;br /&gt;
&lt;br /&gt;
=== How does MarkLogic scale horizontally? ===&lt;br /&gt;
Documents in MarkLogic belong to a database. Within a database are one or more servers.  Each server may contain zero or more &amp;quot;forests&amp;quot;. Within each forest are one or more &amp;quot;stands&amp;quot;. Within each stand are one or more &amp;quot;trees&amp;quot;. A document is hierarchical so it is called a &amp;quot;tree&amp;quot;.  (MarkLogic uses the terms &amp;quot;stand&amp;quot; and &amp;quot;forest&amp;quot; instead of &amp;quot;shard&amp;quot;, but they have the same meaning.) &lt;br /&gt;
&lt;br /&gt;
A client contacts one of the servers in a MarkLogic cluster and initiates a query or search. Because MarkLogic communicates through REST web services, a load balancer can spread requests across the servers in a MarkLogic cluster.  The initiating server does the following&lt;br /&gt;
#it validates the query request from the client&lt;br /&gt;
#it parses and optimizes the query &lt;br /&gt;
#it sends the query to all servers that have forests in the database&lt;br /&gt;
##each server sends it to its forests &lt;br /&gt;
##each forest sends it to each stand &lt;br /&gt;
##each stand uses its indexes to find matching documents&lt;br /&gt;
###all stands and forests query the indexes in parallel&lt;br /&gt;
##forests combine the matching document IDs from all their stands&lt;br /&gt;
##forests sort the matching document IDs (in relevance score order or value order)&lt;br /&gt;
##when complete, each forest returns a sorted iterator to the initiating server&lt;br /&gt;
#when each forest has returned an iterator&lt;br /&gt;
#it walks the sorted iterators from all the forests and combines the results in sorted &lt;br /&gt;
#it retrieves matching documents from its &#039;&#039;Expanded Tree Cache&#039;&#039; or from the forests when documents are not cached&lt;br /&gt;
##forests retrieve documents from their &#039;&#039;Compressed Tree Cache&#039;&#039; or from disk when documents are not cached&lt;br /&gt;
#it filters returned documents to remove false positive matches &lt;br /&gt;
#it optionally transforms documents &lt;br /&gt;
##it creates new documents by extracting matching elements, changing structure, changing file format, etc.&lt;br /&gt;
#it returns all matching (optionally transformed) documents to the requester&lt;br /&gt;
#it saves resulting document IDs when paging query results, so it can return subsequent pages of matching documents in subsequent requests&lt;br /&gt;
&lt;br /&gt;
The initiating server&#039;s process is CPU intensive, serialized, and blocks while waiting on forests. To prevent this from being a bottleneck to the cluster, you can dedicate nodes in the cluster to do nothing but evaluate queries. These are called e-nodes (evaluation nodes). These nodes don&#039;t hold data. If they held data, the &#039;&#039;serialized&#039;&#039; evaluation process would compete with the &#039;&#039;parallel&#039;&#039; index matching process.  Instead e-nodes are dedicated to validating, parsing, sorting, filtering, transforming, and paginating documents. They cache documents in the &#039;&#039;Expanded Tree Cache&#039;&#039; to minimize the number of documents they have to retrieve from data nodes (d-nodes). D-nodes only do parallel index processing and sorting. They cache documents in their &#039;&#039;Compressed Tree Cache&#039;&#039; to reduce disk IO. &lt;br /&gt;
&lt;br /&gt;
=== How do you optimize a MarkLogic cluster to run queries faster? ===&lt;br /&gt;
*E-nodes and d-nodes can be scaled independently to match the load. &lt;br /&gt;
*You can optimize an e-node by minimizing its &#039;&#039;Compressed Tree Cache&#039;&#039; and maximizing its &#039;&#039;Expanded Tree Cache&#039;&#039;. An e-node needs a big &#039;&#039;Expanded Tree Cache&#039;&#039; so it doesn&#039;t have to retrieve as many documents from d-nodes. An e-node doesn&#039;t need a &#039;&#039;Compressed Tree Cache&#039;&#039; because it doesn&#039;t have any data.&lt;br /&gt;
*You can optimize a d-node by doing the opposite of the e-node: maximize the &#039;&#039;Compressed Tree Cache&#039;&#039; and minimize the &#039;&#039;Expanded Tree Cache&#039;&#039;. You can also optimize d-nodes by making sure each d-node runs on similar hardware and that each forest has a similar number of documents. This is important because all forests process queries in parallel and the slowest forest holds up each query: e-nodes have to wait until the slowest forest finishes.&lt;br /&gt;
*You can optimize a query by making it unfiltered.&lt;br /&gt;
**This means it is completely resolved by the indexes. Because no filtering is required, the initiating server doesn&#039;t have to verify that documents match.&lt;br /&gt;
*You can optimize a query by eliminating false positives.  &lt;br /&gt;
**False positives occur when a query identifies a possible match for a document, but it cannot prove it is a match until the filtering process opens the document and verifies it. &lt;br /&gt;
**False positives happen because MarkLogic only partially indexes certain document items. MarkLogic cannot index everything because it would take too much time and space. For example, MarkLogic has a structure index. It indexes relationships between elements in a document.  MarkLogic cannot afford to index each element&#039;s path from itself to every other element. MarkLogic compromises on indexing only parent/child relationships. This is effective in eliminating most non-matching documents, but it can produce false positives.  The only way to know if a document is an &#039;&#039;exact&#039;&#039; match, MarkLogic must open the document and verify it.&lt;br /&gt;
**For example, suppose a query searches for the following path: &amp;lt;br&amp;gt;&amp;lt;code&amp;gt;books/poetry/poem&amp;lt;/code&amp;gt;&amp;lt;br&amp;gt; The structure index will match documents containing books/poetry and poetry/poem. The resulting documents are a probable match, but could contain false positives, such as &amp;lt;br&amp;gt;&amp;lt;code&amp;gt;books/poetry/fantasy/poetry/poem&amp;lt;/code&amp;gt;.&lt;br /&gt;
**You can eliminate false positive structures queries by giving elements unique names. They are  unique no matter where in they are in the structure and they are more self-descriptive.  Instead of naming an element &amp;quot;line&amp;quot; which can mean many things, you can use the precise name  &amp;quot;poemTextLine&amp;quot;. &lt;br /&gt;
*You can optimize a query by greatly limiting how many documents it matches. Design each query to return as few documents as possible. &lt;br /&gt;
**It is expensive to transmit documents. Matching documents have to travel from stands to forests to the initiating server, and to the requester. &lt;br /&gt;
**It is expensive to process documents on the initiating server and the requester. &lt;br /&gt;
**It takes processing time on d-nodes to compare lists of document IDs. The fewer the matching document IDs in one part of the query, the faster the entire query runs. &lt;br /&gt;
**The more matching document IDs, the more work MarkLogic has to do in a d-node to compare, union, intersect, and subract them from matching document IDs returned by other parts of the query. &lt;br /&gt;
**The more matching document IDs, the more sorting MarkLogic has to do in the stands, forests, and initiating server.&lt;br /&gt;
&lt;br /&gt;
=== How does a MarkLogic query compare to map/reduce? ===&lt;br /&gt;
A MarkLogic query or search is similar to map/reduce.  When you query or search for documents in a database, MarkLogic spreads the work across all the servers to be executed in parallel. This is like a &#039;&#039;map&#039;&#039; process because indexes filter out non-matching documents by combining term, range, and semantic indexes according to the query map. The results are then &#039;&#039;reduced&#039;&#039; at the forest level and again at the database level and again at the initiating server. This parallel division of responsibilities enables MarkLogic to scale.&lt;br /&gt;
&lt;br /&gt;
== Term, Range, and Semantic Indexes ==&lt;br /&gt;
MarkLogic indexes are not B-Tree indexes. MarkLogic uses &#039;&#039;&#039;term&#039;&#039;&#039;, &#039;&#039;&#039;range&#039;&#039;&#039;, and &#039;&#039;&#039;semantic&#039;&#039;&#039; indexes. &lt;br /&gt;
*&#039;&#039;&#039;A term index&#039;&#039;&#039; associates a term with every document that contains the term.  For example, in a word index, every word in the database is stored in the index. Associated with each word in the index is a list of each document ID that contains the term.  &lt;br /&gt;
*&#039;&#039;&#039;A range index&#039;&#039;&#039; is a double term index: it contains each term and all document IDs that contain that term, and it contains each document ID and all the terms that are in the document.&lt;br /&gt;
*&#039;&#039;&#039;A semantic index&#039;&#039;&#039; is similar to a range index but it is optimized to store triples (three pieces of data: subject, object, and predicate).&lt;br /&gt;
&lt;br /&gt;
Term indexes are fast. Give the index a term, and with one lookup, it returns &#039;&#039;all&#039;&#039; documents that contain the term. Term indexes are memory mapped files. They run in RAM unless you run out of RAM and then firmware in the CPU efficiently swaps them to and from disk. Thus, it is best to have enough RAM in a MarkLogic server to contain all indexes in memory.&lt;br /&gt;
&lt;br /&gt;
Unlike B-Tree indexes, term indexes are easily sharded within and between servers. MarkLogic takes advantage of this to run queries in parallel within and across servers. This is how MarkLogic can scale to billions of documents and still return queries and searches in milliseconds.&lt;br /&gt;
&lt;br /&gt;
When documents are inserted or updated, MarkLogic indexes them in RAM (as well as appends the changes to a journal on disk). When documents in RAM start to consume too much RAM, MarkLogic writes them to disk as a &amp;quot;stand&amp;quot; in a &amp;quot;forest&amp;quot; and starts creating a new &amp;quot;stand&amp;quot; in RAM.  &lt;br /&gt;
&lt;br /&gt;
When you query or search for documents, MarkLogic goes to the indexes in the stands (which are cached in RAM) and evaluates the query in parallel. Each stand index returns a list of document IDs (a list of numbers) that match the query. MarkLogic takes the document IDs returned by each stand and merges them into a final list of document IDs, whcih it uses to retrieve the documents from cache or disk. This works well because computers are very fast at sort merging lists of numbers.&lt;br /&gt;
&lt;br /&gt;
MarkLogic uses the same indexes for both queries and searches. This allows you to combine search and query expressions. The main difference between search and query is how documents are sorted: searches sort by relevance and queries sort by values. Another difference is that queries tend to use value indexes and searches tend to use word and phrase indexes. &lt;br /&gt;
&lt;br /&gt;
=== What specific indexes does MarkLogic have? ===&lt;br /&gt;
MarkLogic uses indexes to extract words, values, structures, and links out of documents. An index is an altered view of a document. It enables you to search and query for documents &amp;lt;br&amp;gt;&#039;&#039;&#039;as if they contained only:&#039;&#039;&#039;&lt;br /&gt;
*&#039;&#039;&#039;Words:&#039;&#039;&#039; a flat set of words without structure, such as &amp;lt;br&amp;gt;&amp;lt;code&amp;gt;[&amp;quot;Mary&amp;quot;, &amp;quot;had&amp;quot;, &amp;quot;a&amp;quot;, &amp;quot;little&amp;quot;, &amp;quot;lamb&amp;quot;]&amp;lt;/code&amp;gt;&lt;br /&gt;
*&#039;&#039;&#039;Phrases:&#039;&#039;&#039; a flat set of phrases without structure, such as &amp;lt;br&amp;gt;&amp;lt;code&amp;gt;[&amp;quot;Mary had&amp;quot;, &amp;quot;had a&amp;quot;, &amp;quot;a little&amp;quot;, &amp;quot;little lamb&amp;quot;]&amp;lt;/code&amp;gt;&lt;br /&gt;
*&#039;&#039;&#039;Elements:&#039;&#039;&#039; a flat set of elements without values, such as &amp;lt;br&amp;gt;&amp;lt;code&amp;gt;[&amp;quot;poem&amp;quot;, &amp;quot;text&amp;quot;, &amp;quot;line&amp;quot;]&amp;lt;/code&amp;gt;&lt;br /&gt;
*&#039;&#039;&#039;Element-values:&#039;&#039;&#039; a flat set of elements with string values, such as &amp;lt;br&amp;gt;&amp;lt;code&amp;gt;&amp;quot;line&amp;quot;: &amp;quot;Mary had a little lamb&amp;quot;&amp;lt;/code&amp;gt;&lt;br /&gt;
*&#039;&#039;&#039;Element-words:&#039;&#039;&#039; a flat set of elements with words, such as &amp;lt;br&amp;gt;&amp;lt;code&amp;gt;&amp;quot;line&amp;quot;: [&amp;quot;Mary&amp;quot;, &amp;quot;had&amp;quot;, &amp;quot;a&amp;quot;, &amp;quot;little&amp;quot;, &amp;quot;lamb&amp;quot;]&amp;lt;/code&amp;gt;&lt;br /&gt;
*&#039;&#039;&#039;Element-phrases:&#039;&#039;&#039; a flat set of elements with phrases, such as &amp;lt;br&amp;gt;&amp;lt;code&amp;gt;&amp;quot;line&amp;quot;: [&amp;quot;Mary had&amp;quot;, &amp;quot;had a&amp;quot;, &amp;quot;a little&amp;quot;, &amp;quot;little lamb&amp;quot;]&amp;lt;/code&amp;gt;&lt;br /&gt;
*&#039;&#039;&#039;Element-value lexicon:&#039;&#039;&#039; a flat set of elements with typed values, such as &amp;lt;br&amp;gt;&amp;lt;code&amp;gt;&amp;quot;lineSequence&amp;quot;: 3&amp;lt;/code&amp;gt;&amp;lt;br&amp;gt; or a list, count, or co-occurrence of element values scoped to a database, set of documents, or one document.&lt;br /&gt;
*&#039;&#039;&#039;XPath-structure-value lexicon:&#039;&#039;&#039; a flat set of hierarchical elements with typed values, such as &amp;lt;br&amp;gt;&amp;lt;code&amp;gt;poem.text.line.lineSequence: 3&amp;lt;/code&amp;gt;&amp;lt;br&amp;gt; or a list, count, or co-occurrence of hierarchical element values scoped to a database, set of documents, or one document.&lt;br /&gt;
*&#039;&#039;&#039;XPath-structure:&#039;&#039;&#039;hierarchical structures without values, such as &amp;lt;br&amp;gt;&amp;lt;code&amp;gt;poem.text.line&amp;lt;/code&amp;gt;&lt;br /&gt;
*&#039;&#039;&#039;XPath-structure-words:&#039;&#039;&#039; hierarchical structures with words, such as &amp;lt;br&amp;gt;&amp;lt;code&amp;gt;poem.text.line: [&amp;quot;Mary&amp;quot;, &amp;quot;had&amp;quot;, &amp;quot;a&amp;quot;, &amp;quot;little&amp;quot;, &amp;quot;lamb&amp;quot;]&amp;lt;/code&amp;gt;&lt;br /&gt;
*&#039;&#039;&#039;XPath-structure-phrases:&#039;&#039;&#039; hierarchical structures with phrases, such as &amp;lt;br&amp;gt;&amp;lt;code&amp;gt;poem.text.line: [&amp;quot;Mary had&amp;quot;, &amp;quot;had a&amp;quot;, &amp;quot;a little&amp;quot;, &amp;quot;little lamb&amp;quot;]&amp;lt;/code&amp;gt;&lt;br /&gt;
*&#039;&#039;&#039;XPath-structure-values:&#039;&#039;&#039; hierarchical structures with values, such as &amp;lt;br&amp;gt;&amp;lt;code&amp;gt;poem.text.line: &amp;quot;Mary had a little lamb&amp;quot;&amp;lt;/code&amp;gt;&lt;br /&gt;
*&#039;&#039;&#039;RDF document links&#039;&#039;&#039; to other documents, such as &amp;lt;br&amp;gt;&amp;lt;code&amp;gt;{&amp;quot;subject&amp;quot;: &amp;quot;http://example.org/documents/thisDoc&amp;quot;, &amp;lt;br&amp;gt;&amp;quot;predicate&amp;quot;: &amp;quot;http://example.org/predicates/relatesSomehowTo&amp;quot;, &amp;lt;br&amp;gt;&amp;quot;object&amp;quot;: &amp;quot;http://example.org/documents/thatDoc&amp;quot;}&amp;lt;/code&amp;gt;&lt;br /&gt;
*&#039;&#039;&#039;RDF abstract links&#039;&#039;&#039; to other abstract concepts, such as &amp;lt;br&amp;gt;&amp;lt;code&amp;gt;{&amp;quot;subject&amp;quot;: &amp;quot;http://example.org/documents/thisDoc&amp;quot;, &amp;lt;br&amp;gt;&amp;quot;predicate&amp;quot;: &amp;quot;http://example.org/predicates/relatesSomehowTo&amp;quot;, &amp;lt;br&amp;gt;&amp;quot;object&amp;quot;: &amp;quot;http://example.org/documents/someConceptWithNoDocumentAtTheURI&amp;quot;}&amp;lt;/code&amp;gt;&lt;br /&gt;
*&#039;&#039;&#039;RDF data links&#039;&#039;&#039; to data, such as &amp;lt;br&amp;gt;&amp;lt;code&amp;gt;{&amp;quot;subject&amp;quot;: &amp;quot;http://example.org/documents/thisDoc&amp;quot;, &amp;lt;br&amp;gt;&amp;quot;predicate&amp;quot;: &amp;quot;http://example.org/predicates/ageInYears&amp;quot;, &amp;lt;br&amp;gt;&amp;quot;object&amp;quot;: 12}&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
MarkLogic can combine any of these indexes in any way to find matching documents.  It can sort the result by relevance or by value. &lt;br /&gt;
&lt;br /&gt;
Search and query expressions are fully composable; i.e. they can be nested inside each other and combined using AND, OR, and NOT expressions.&lt;br /&gt;
&lt;br /&gt;
== Training Resources for MarkLogic Search ==&lt;br /&gt;
* [http://developer.marklogic.com/blog/grokking-the-cts-api &amp;quot;Grokking the cts API&amp;quot;] is a great overview of MarkLogic&#039;s search and query capabilities.&lt;br /&gt;
&lt;br /&gt;
[[Category: MarkLogic]]&lt;/div&gt;</summary>
		<author><name>Bowersmt</name></author>
	</entry>
	<entry>
		<id>https://tech.churchofjesuschrist.org/wiki/index.php?title=What_is_MarkLogic%3F&amp;diff=70567</id>
		<title>What is MarkLogic?</title>
		<link rel="alternate" type="text/html" href="https://tech.churchofjesuschrist.org/wiki/index.php?title=What_is_MarkLogic%3F&amp;diff=70567"/>
		<updated>2014-11-14T08:53:55Z</updated>

		<summary type="html">&lt;p&gt;Bowersmt: Fixed heading&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;br /&gt;
[[MarkLogic|« Back to MarkLogic]]&lt;br /&gt;
&lt;br /&gt;
== Describing MarkLogic ==&lt;br /&gt;
[http://www.marklogic.com/what-is-marklogic/ MarkLogic] is a [http://www.marklogic.com/what-is-marklogic/inside-marklogic/ &#039;&#039;&#039;REST application server&#039;&#039;&#039;, &#039;&#039;&#039;document database&#039;&#039;&#039;, and &#039;&#039;&#039;search engine&#039;&#039;&#039;]. It is REST through and through. It is built specifically for hypertext documents, links, metadata, URIs, MIME types, and HTTP. It is schema-agnostic because it is automatically aware of the independent structure of each of its JSON and XML documents. It is search-centric because it can search for &#039;&#039;any combination&#039;&#039; of words, values, structures, and links within and across documents. It scales horizontally to hundreds of servers within and between data centers while maintaining ACID-compliant transactions. &lt;br /&gt;
&lt;br /&gt;
MarkLogic has the following [http://www.marklogic.com/what-is-marklogic/enterprise-nosql/ enterprise features]:&lt;br /&gt;
* [http://www.marklogic.com/resources/java-developers-guide/ Java APIs]&lt;br /&gt;
* [http://en.wikipedia.org/wiki/Node.js Node.js APIs]&lt;br /&gt;
* [http://developer.marklogic.com/learn/2009-07-search-api-walkthrough Search] and [http://developer.marklogic.com/learn/arch/search-and-indexing Query]&lt;br /&gt;
* [http://www.marklogic.com/blog/can-you-pass-the-acid-test/ ACID Transactions]&lt;br /&gt;
* [http://www.marklogic.com/resources/marklogic-high-availability-and-disaster-recovery/resource_download/datasheets/ High Availability] and [http://docs.marklogic.com/guide/database-replication/dbrep_intro#chapter Disaster Recovery]&lt;br /&gt;
* [http://www.marklogic.com/resources/marklogic-flexible-replication/resource_download/datasheets/ Replication within and across data centers]&lt;br /&gt;
* [http://docs.marklogic.com/guide/admin/security#chapter Government-grade Security]&lt;br /&gt;
* [https://docs.marklogic.com/guide/cluster.pdf Scalability] and [https://docs.marklogic.com/guide/admin/database-rebalancing#chapter Elasticity]&lt;br /&gt;
* [https://docs.marklogic.com/guide/ec2/managing#chapter On-premise or Cloud Deployment (especially AWS)]&lt;br /&gt;
* [http://www.marklogic.com/resources/marklogic-and-hadoop/resource_download/datasheets/ Hadoop for Storage and Compute]&lt;br /&gt;
* [http://www.marklogic.com/resources/marklogic-semantics-mlw14/ Semantics]&lt;br /&gt;
&lt;br /&gt;
== What is REST? ==&lt;br /&gt;
REST is an architectural style that uses a uniform resource identifier (&#039;&#039;&#039;URI&#039;&#039;&#039;) and a web protocol (&#039;&#039;&#039;HTTP/HTTPS&#039;&#039;&#039;) to request and transfer a representation (&#039;&#039;&#039;MIME media type&#039;&#039;&#039;) of the state of a resource (&#039;&#039;&#039;document&#039;&#039;&#039;) at a point in time from a server to a client. &lt;br /&gt;
&lt;br /&gt;
REST was coined and defined by Roy Fielding in his &lt;br /&gt;
[http://www.ics.uci.edu/~fielding/pubs/dissertation/top.htm dissertation, &#039;&#039;Architectural Styles and the Design of Network-based Software Architectures&#039;&#039;].  REST standardizes and documents the patterns used in the world wide web: self-documenting hypertext with data and metadata (HTML), stateless request/response communication protocol (HTTP/HTTPS), resource locators (URL), multiple representations per URL (MIME types), and downloading code on demand to process resources (JavaScript, CSS, etc.).&lt;br /&gt;
&lt;br /&gt;
REST consists of three main concepts: &lt;br /&gt;
* (RE) Representation&lt;br /&gt;
* (S)  State &lt;br /&gt;
* (T)  Transfer &lt;br /&gt;
&lt;br /&gt;
== Why is MarkLogic RESTful? ==&lt;br /&gt;
&lt;br /&gt;
=== &#039;&#039;&#039;Representation and MarkLogic&#039;&#039;&#039; === &lt;br /&gt;
* A representation is a document that represents a resource. It has three requirements: MIME media type, URI, and hypertext.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;MIME type:&#039;&#039;&#039; Each resource can be represented by one or more types of documents. The MIME media type defines the representation a client requests. A client may request the resource to be represented as JSON, XML, HTML, PNG, PDF, etc. &lt;br /&gt;
**&#039;&#039;&#039;MarkLogic&#039;&#039;&#039; stores any type of document and assigns the appropriate [http://developer.marklogic.com/blog/document-formats-part2 MIME type] to it. It can fully index, query, search, and process JSON, XML, and RDF documents. It meets the REST requirement of being able to transform JSON, XML, and RDF documents into any other MIME type. It knows how to execute JavaScript, XQuery, XSLT, and SPARQL documents. It knows how [http://docs.marklogic.com/guide/cpf/default#chapter to transform into XHTML] the content, formatting, and structure of Microsoft Word, PowerPoint, Excel, textual PDF, DocBook, and CSS  documents. (It can also use Microsoft Office to create, edit, and manage content in MarkLogic.) It knows how to [https://docs.marklogic.com/guide/search-dev/binary-document-metadata extract metadata and text from over 138 types of binary documents], such as raster images, vector images, videos, archive files, database files, encoded emails, presentations, spreadsheets, word-processing documents, text formats. &lt;br /&gt;
**Few NoSQL databases use MIME types to identify the media type of each document.  Most NoSQL databases support only one type of data and it is usually proprietary: columnar, BSON, binary, etc. Most cannot transform from one MIME type to another.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;URI:&#039;&#039;&#039; A resource is identified by a globally unique identifier (URI). &#039;&#039;&#039;MarkLogic&#039;&#039;&#039; identifies each document with a [http://developer.marklogic.com/try/rest/page2 unique URI]. A document in MarkLogic is like a row in a table in a schema in a relational database. A URI is liberating. It provides random access to any resource anywhere. It is like being able to retrieve any row in any table in any schema of a relational database without having to know what table and schema the row is stored in.  &lt;br /&gt;
**Navigating URL hierarchy is fundamental to REST. MarkLogic understands the hierarchy within a URI, which is represented by slashes &amp;quot;/&amp;quot;, such as https://www.lds.org/scriptures/ot/gen/1  MarkLogic treats the items between the slashes as folders. The URI of each document automatically places it in a folder in a folder hierarchy. A URI automatically defines the folder hierarchy.  In the example URI above, the document for Genesis chapter 1, is located in the Genesis folder, which is located in the Old Testament folder, which is located in the Scriptures folder on lds.org.  &#039;&#039;&#039;MarkLogic&#039;&#039;&#039; indexes the documents in each folder and its subfolders. This makes it fast and easy to retrieve any or all documents in any folder and/or its subfolders.&lt;br /&gt;
**Few NoSQL databases use the URI as the primary key for their documents or data. They also don&#039;t index the URI hierarchically to filter documents by folder and subfolder.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Hypertext:&#039;&#039;&#039; A document should contain data that represents the resource. The data should be &#039;&#039;&#039;human readable and self-documenting&#039;&#039;&#039;, like JSON, XML, RDF, and HTML. It should be &#039;&#039;&#039;linked data&#039;&#039;&#039; (i.e. the &amp;quot;hyper&amp;quot; in &amp;quot;hypertext&amp;quot;). A document should contain &#039;&#039;&#039; metadata links&#039;&#039;&#039; about the resource, such as RDF. It should contain &#039;&#039;&#039;action links&#039;&#039;&#039; to define what further actions can be done with the resource. It should contain &#039;&#039;&#039;related links&#039;&#039;&#039; to related resources, such as images, audio, video, related documents, etc. Each related link should define what actions can be done with the referenced resource, such as download it, display a link to it, execute a command against it, etc.)&lt;br /&gt;
**&#039;&#039;&#039;Hypertext&#039;&#039;&#039; or &#039;&#039;&#039;hypermedia&#039;&#039;&#039; documents must have all these features. Hyperlinks are what the &amp;quot;hyper&amp;quot; in hypertext and hypermedia refers to.  You can&#039;t have REST without &#039;&#039;metadata links&#039;&#039; to define what the data means, &#039;&#039;action links&#039;&#039; to know how to work with the resource, and &#039;&#039;related links&#039;&#039; to connect resources. It should all be human readable and self-documenting so a developer does not have to read documentation to know how to interact with a REST web service and its documents. &lt;br /&gt;
** &#039;&#039;&#039;MarkLogic&#039;&#039;&#039; meets all the requirements for hypertext representation. It is designed around MIME types, URIs, and Linked data.  It stores documents with their MIME types as [http://www.w3schools.com/json/ JSON], [http://www.w3schools.com/xml/ XML], [http://www.w3schools.com/webservices/ws_rdf_intro.asp RDF], [http://www.w3schools.com/html/ HTML], etc.  These documents are human-readable and self-documenting, which MarkLogic leverages to recognize and index each document&#039;s data, data structure, metadata links, action links, and related links. This makes it easy to &#039;&#039;&#039;search&#039;&#039;&#039;, &#039;&#039;&#039;query&#039;&#039;&#039;, &#039;&#039;&#039;transform&#039;&#039;&#039;, and &#039;&#039;&#039;deliver&#039;&#039;&#039; hypertext documents.  MarkLogic can also store any type of binary document and deliver it as a related resource, such as an image, video, or audio. MarkLogic is designed to process simple links and RDF links using [http://en.wikipedia.org/wiki/SPARQL SPARQL] and [https://docs.marklogic.com/xinc XInclude]. MarkLogic can represent links in many formats:  [https://docs.marklogic.com/xp XPointer], [https://docs.marklogic.com/guide/semantics/loading#id_97709 RDF/XML], [https://docs.marklogic.com/guide/semantics/loading#id_79194 RDF/JSON], [https://docs.marklogic.com/guide/semantics/loading#id_73211 Turtle], [https://docs.marklogic.com/guide/semantics/loading#id_70596 N-Triples], [https://docs.marklogic.com/guide/semantics/loading#id_61596 N-Quads], and [https://docs.marklogic.com/guide/semantics/loading#id_74485 TriG].&lt;br /&gt;
**No other NoSQL database natively indexes and fully processes all the document types required for REST hypertext: JSON, XML, RDF, HTML, CSS, and JavaScript.&lt;br /&gt;
&lt;br /&gt;
=== &#039;&#039;&#039;State and MarkLogic&#039;&#039;&#039; === &lt;br /&gt;
* State in REST exists on the client and in server documents. It does not exist in the communications protocol or in the server as cached session data. &lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Server:&#039;&#039;&#039; All information needed to process a request must be presented in the request and processed against documents in the database. State must only be in the request and in database documents: state cannot be anywhere else, such as in a session cache. The documents in the server define the state of the server. A REST server should explicitly create a state machine that defines the acceptable actions that can transacted against documents in specific contexts.&lt;br /&gt;
**A REST transaction occurs at a &#039;&#039;&#039;point in time&#039;&#039;&#039;. The state of the data in the request is unchanging, but the state of the documents and state machines in the database are often changing. Since request state and database state are both required to process the request and since shifting state creates unpredictable results, a REST transaction should run at a point in time with unchanging state. Only an ACID-compliant database can ensure consistent state because it isolates each transaction from every other transaction. The only time REST does not need an ACID-compliant database is when database documents do not change, database state machines do not change, or when clients can live with the resultant level of unreliable and unpredictable results.&lt;br /&gt;
**&#039;&#039;&#039;MarkLogic&#039;&#039;&#039; meets all the requirements for REST state.  Its web services are stateless: there is no session cache. It is ACID compliant. It ensures each transaction occurs at a point in time and is isolated from all other transactions. This ensures consistent processing during a transaction -- even across billions of documents. MarkLogic is an [http://en.wikipedia.org/wiki/Multiversion_concurrency_control MVCC] database which provides transaction isolation without slowing the performance of reads -- even when documents being read are being modified simultaneously by other transactions. (Also, like any other ACID database, when multiple updates and deletes compete for the same documents, they will impact each other&#039;s performance because change has to be serialized.)  &lt;br /&gt;
** Most other NoSQL databases are not ACID compliant. They are only suitable for REST services when their documents or data do not change or when the rate of change is slow enough or dispersed enough that it creates an acceptable level of unreliability and unpredictability.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Client:&#039;&#039;&#039; A REST client, such as a web browser or spider, locally maintains transactional state, such as what to do in response to documents and result codes that are returned from server transactions. An application exists only in the client -- not in the server (although, a server may deliver application code to a client, such as when a web server downloads HTML, CSS, and JavaScript to a browser). Client application code decides when to execute web service calls and it ties the results together to accomplish its purpose. This allows multiple authorized applications to reuse web services for a variety of purposes.  &lt;br /&gt;
**The server helps the client know what web service calls are available by providing action links with each response.  Action links are contextual and the context is based on the application account, user account, database documents, links within and between documents, the server state machine, etc. Through action links, the server can inform a client application what web service calls are permissible in any given context.&lt;br /&gt;
**&#039;&#039;&#039;MarkLogic&#039;&#039;&#039; meets the needs of client applications through its built-in ability to process and send action links to clients based on context. MarkLogic supports RDF triples and SPARQL, which enables context to be defined across applications, users, document state, links between documents, server state machine, etc. MarkLogic processes triples very quickly, which enables context to scale to billions of documents, millions of users, etc.&lt;br /&gt;
**&#039;&#039;&#039;MarkLogic&#039;&#039;&#039; also uses application and user permissions to filter which documents are returned to clients.  MarkLogic does this automatically and transparently by adding security filtering constraints into every search and query. This ensures no account can access unauthorized documents. This is fast because all security permissions are built-into MarkLogic&#039;s indexes -- which allows document-level security to scale across billions of documents.&lt;br /&gt;
** Most other NoSQL databases do not provide government-grade, document-level security and they also do not support RDF triples and SPARQL.&lt;br /&gt;
&lt;br /&gt;
Because MarkLogic can provide both the web service and database in one server, it is easy to use the state of the documents and the &lt;br /&gt;
&lt;br /&gt;
=== &#039;&#039;&#039;Transfer and MarkLogic&#039;&#039;&#039; === &lt;br /&gt;
* &#039;&#039;&#039;Transfer&#039;&#039;&#039; in REST is a communication protocol that enables a client to send a hypertext request to a server and receive back a hypertext response. The transfer must be stateless and be a request/response protocol. It must have human readable, self-descriptive headers.  The header must contain metadata about the request, such as the requested resource URI, MIME type of the resource, action to perform on the resource (such as get, put, post, patch, and delete). [http://www.w3schools.com/tags/ref_httpmethods.asp &#039;&#039;&#039;HTTP&#039;&#039;&#039;] (Hypertext transfer protocol) and &#039;&#039;&#039;HTTPS&#039;&#039;&#039; (secure HTTP) are designed specifically for REST (that is why they have &amp;quot;hypertext&amp;quot; in their name).&lt;br /&gt;
&lt;br /&gt;
* All &#039;&#039;&#039;MarkLogic&#039;&#039;&#039; communication is through through HTTP and HTTPS REST services (except for its SQL JDBC feature). This includes all internal cluster communication.  MarkLogic provides out-of-the-box REST interfaces for manipulating resources (insert, update, delete, query, search, transform, etc.) and administering MarkLogic (REST app servers, databases, indexes, clusters, etc).  MarkLogic makes it very easy to create custom REST services because everything in MarkLogic is built around REST and because they provide simple and powerful application server APIs.&lt;br /&gt;
&lt;br /&gt;
== MarkLogic Links ==&lt;br /&gt;
*[[MarkLogic]]&lt;br /&gt;
*[[MarkLogic Query and Search]]&lt;br /&gt;
*[[MarkLogic Training Resources]]&lt;br /&gt;
*[[Installing MarkLogic]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[Category: MarkLogic]]&lt;/div&gt;</summary>
		<author><name>Bowersmt</name></author>
	</entry>
	<entry>
		<id>https://tech.churchofjesuschrist.org/wiki/index.php?title=MarkLogic_Training_Resources&amp;diff=70566</id>
		<title>MarkLogic Training Resources</title>
		<link rel="alternate" type="text/html" href="https://tech.churchofjesuschrist.org/wiki/index.php?title=MarkLogic_Training_Resources&amp;diff=70566"/>
		<updated>2014-11-14T08:52:42Z</updated>

		<summary type="html">&lt;p&gt;Bowersmt: Fixed heading&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[[MarkLogic|« Back to MarkLogic]]&lt;br /&gt;
&lt;br /&gt;
== MarkLogic Provided Training ==&lt;br /&gt;
* [http://developer.marklogic.com/blog/grokking-the-cts-api &amp;quot;Grokking the cts API&amp;quot;] is a great overview of MarkLogic&#039;s search and query capabilities, which are its most important feature.  Everything you do in MarkLogic should be focused around how MarkLogic indexes, searches, and queries documents.&lt;br /&gt;
&lt;br /&gt;
* [http://developer.marklogic.com/try/ninja/index Try Marklogic] is the best way to play with MarkLogic&#039;s search and query features.  Without installing anything, you can run queries and searches against an existing database in the cloud.&lt;br /&gt;
&lt;br /&gt;
* [http://developer.marklogic.com/learn MarkLogic Tutorials] guide you step-by-step through each major MarkLogic feature.  Some tutorials are short and sweet five minutes, and others take up to an hour or so.&lt;br /&gt;
&lt;br /&gt;
* [https://mlu.marklogic.com/registration/ Live Training] is available from MarkLogic at no cost.  A live instructor will work with you to show you how to build MarkLogic applications, administer MarkLogic, use Semantics (triples), and MarkLogic fundamentals (like search and queries).&lt;br /&gt;
&lt;br /&gt;
[[Category:MarkLogic]]&lt;/div&gt;</summary>
		<author><name>Bowersmt</name></author>
	</entry>
	<entry>
		<id>https://tech.churchofjesuschrist.org/wiki/index.php?title=MarkLogic_Training_Resources&amp;diff=70565</id>
		<title>MarkLogic Training Resources</title>
		<link rel="alternate" type="text/html" href="https://tech.churchofjesuschrist.org/wiki/index.php?title=MarkLogic_Training_Resources&amp;diff=70565"/>
		<updated>2014-11-14T08:51:55Z</updated>

		<summary type="html">&lt;p&gt;Bowersmt: Added back to marklogic link&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[[MarkLogic|« Back to MarkLogic]]&lt;br /&gt;
&lt;br /&gt;
== MarkLogic Training Resources ==&lt;br /&gt;
* [http://developer.marklogic.com/blog/grokking-the-cts-api &amp;quot;Grokking the cts API&amp;quot;] is a great overview of MarkLogic&#039;s search and query capabilities, which are its most important feature.  Everything you do in MarkLogic should be focused around how MarkLogic indexes, searches, and queries documents.&lt;br /&gt;
&lt;br /&gt;
* [http://developer.marklogic.com/try/ninja/index Try Marklogic] is the best way to play with MarkLogic&#039;s search and query features.  Without installing anything, you can run queries and searches against an existing database in the cloud.&lt;br /&gt;
&lt;br /&gt;
* [http://developer.marklogic.com/learn MarkLogic Tutorials] guide you step-by-step through each major MarkLogic feature.  Some tutorials are short and sweet five minutes, and others take up to an hour or so.&lt;br /&gt;
&lt;br /&gt;
* [https://mlu.marklogic.com/registration/ Live Training] is available from MarkLogic at no cost.  A live instructor will work with you to show you how to build MarkLogic applications, administer MarkLogic, use Semantics (triples), and MarkLogic fundamentals (like search and queries).&lt;br /&gt;
&lt;br /&gt;
[[Category:MarkLogic]]&lt;/div&gt;</summary>
		<author><name>Bowersmt</name></author>
	</entry>
	<entry>
		<id>https://tech.churchofjesuschrist.org/wiki/index.php?title=What_is_MarkLogic%3F&amp;diff=70564</id>
		<title>What is MarkLogic?</title>
		<link rel="alternate" type="text/html" href="https://tech.churchofjesuschrist.org/wiki/index.php?title=What_is_MarkLogic%3F&amp;diff=70564"/>
		<updated>2014-11-14T08:50:59Z</updated>

		<summary type="html">&lt;p&gt;Bowersmt: Added back to marklogic&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[[MarkLogic|« Back to MarkLogic]]&lt;br /&gt;
&lt;br /&gt;
== What is MarkLogic? ==&lt;br /&gt;
[http://www.marklogic.com/what-is-marklogic/ MarkLogic] is a [http://www.marklogic.com/what-is-marklogic/inside-marklogic/ &#039;&#039;&#039;REST application server&#039;&#039;&#039;, &#039;&#039;&#039;document database&#039;&#039;&#039;, and &#039;&#039;&#039;search engine&#039;&#039;&#039;]. It is REST through and through. It is built specifically for hypertext documents, links, metadata, URIs, MIME types, and HTTP. It is schema-agnostic because it is automatically aware of the independent structure of each of its JSON and XML documents. It is search-centric because it can search for &#039;&#039;any combination&#039;&#039; of words, values, structures, and links within and across documents. It scales horizontally to hundreds of servers within and between data centers while maintaining ACID-compliant transactions. &lt;br /&gt;
&lt;br /&gt;
MarkLogic has the following [http://www.marklogic.com/what-is-marklogic/enterprise-nosql/ enterprise features]:&lt;br /&gt;
* [http://www.marklogic.com/resources/java-developers-guide/ Java APIs]&lt;br /&gt;
* [http://en.wikipedia.org/wiki/Node.js Node.js APIs]&lt;br /&gt;
* [http://developer.marklogic.com/learn/2009-07-search-api-walkthrough Search] and [http://developer.marklogic.com/learn/arch/search-and-indexing Query]&lt;br /&gt;
* [http://www.marklogic.com/blog/can-you-pass-the-acid-test/ ACID Transactions]&lt;br /&gt;
* [http://www.marklogic.com/resources/marklogic-high-availability-and-disaster-recovery/resource_download/datasheets/ High Availability] and [http://docs.marklogic.com/guide/database-replication/dbrep_intro#chapter Disaster Recovery]&lt;br /&gt;
* [http://www.marklogic.com/resources/marklogic-flexible-replication/resource_download/datasheets/ Replication within and across data centers]&lt;br /&gt;
* [http://docs.marklogic.com/guide/admin/security#chapter Government-grade Security]&lt;br /&gt;
* [https://docs.marklogic.com/guide/cluster.pdf Scalability] and [https://docs.marklogic.com/guide/admin/database-rebalancing#chapter Elasticity]&lt;br /&gt;
* [https://docs.marklogic.com/guide/ec2/managing#chapter On-premise or Cloud Deployment (especially AWS)]&lt;br /&gt;
* [http://www.marklogic.com/resources/marklogic-and-hadoop/resource_download/datasheets/ Hadoop for Storage and Compute]&lt;br /&gt;
* [http://www.marklogic.com/resources/marklogic-semantics-mlw14/ Semantics]&lt;br /&gt;
&lt;br /&gt;
== What is REST? ==&lt;br /&gt;
REST is an architectural style that uses a uniform resource identifier (&#039;&#039;&#039;URI&#039;&#039;&#039;) and a web protocol (&#039;&#039;&#039;HTTP/HTTPS&#039;&#039;&#039;) to request and transfer a representation (&#039;&#039;&#039;MIME media type&#039;&#039;&#039;) of the state of a resource (&#039;&#039;&#039;document&#039;&#039;&#039;) at a point in time from a server to a client. &lt;br /&gt;
&lt;br /&gt;
REST was coined and defined by Roy Fielding in his &lt;br /&gt;
[http://www.ics.uci.edu/~fielding/pubs/dissertation/top.htm dissertation, &#039;&#039;Architectural Styles and the Design of Network-based Software Architectures&#039;&#039;].  REST standardizes and documents the patterns used in the world wide web: self-documenting hypertext with data and metadata (HTML), stateless request/response communication protocol (HTTP/HTTPS), resource locators (URL), multiple representations per URL (MIME types), and downloading code on demand to process resources (JavaScript, CSS, etc.).&lt;br /&gt;
&lt;br /&gt;
REST consists of three main concepts: &lt;br /&gt;
* (RE) Representation&lt;br /&gt;
* (S)  State &lt;br /&gt;
* (T)  Transfer &lt;br /&gt;
&lt;br /&gt;
== Why is MarkLogic RESTful? ==&lt;br /&gt;
&lt;br /&gt;
=== &#039;&#039;&#039;Representation and MarkLogic&#039;&#039;&#039; === &lt;br /&gt;
* A representation is a document that represents a resource. It has three requirements: MIME media type, URI, and hypertext.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;MIME type:&#039;&#039;&#039; Each resource can be represented by one or more types of documents. The MIME media type defines the representation a client requests. A client may request the resource to be represented as JSON, XML, HTML, PNG, PDF, etc. &lt;br /&gt;
**&#039;&#039;&#039;MarkLogic&#039;&#039;&#039; stores any type of document and assigns the appropriate [http://developer.marklogic.com/blog/document-formats-part2 MIME type] to it. It can fully index, query, search, and process JSON, XML, and RDF documents. It meets the REST requirement of being able to transform JSON, XML, and RDF documents into any other MIME type. It knows how to execute JavaScript, XQuery, XSLT, and SPARQL documents. It knows how [http://docs.marklogic.com/guide/cpf/default#chapter to transform into XHTML] the content, formatting, and structure of Microsoft Word, PowerPoint, Excel, textual PDF, DocBook, and CSS  documents. (It can also use Microsoft Office to create, edit, and manage content in MarkLogic.) It knows how to [https://docs.marklogic.com/guide/search-dev/binary-document-metadata extract metadata and text from over 138 types of binary documents], such as raster images, vector images, videos, archive files, database files, encoded emails, presentations, spreadsheets, word-processing documents, text formats. &lt;br /&gt;
**Few NoSQL databases use MIME types to identify the media type of each document.  Most NoSQL databases support only one type of data and it is usually proprietary: columnar, BSON, binary, etc. Most cannot transform from one MIME type to another.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;URI:&#039;&#039;&#039; A resource is identified by a globally unique identifier (URI). &#039;&#039;&#039;MarkLogic&#039;&#039;&#039; identifies each document with a [http://developer.marklogic.com/try/rest/page2 unique URI]. A document in MarkLogic is like a row in a table in a schema in a relational database. A URI is liberating. It provides random access to any resource anywhere. It is like being able to retrieve any row in any table in any schema of a relational database without having to know what table and schema the row is stored in.  &lt;br /&gt;
**Navigating URL hierarchy is fundamental to REST. MarkLogic understands the hierarchy within a URI, which is represented by slashes &amp;quot;/&amp;quot;, such as https://www.lds.org/scriptures/ot/gen/1  MarkLogic treats the items between the slashes as folders. The URI of each document automatically places it in a folder in a folder hierarchy. A URI automatically defines the folder hierarchy.  In the example URI above, the document for Genesis chapter 1, is located in the Genesis folder, which is located in the Old Testament folder, which is located in the Scriptures folder on lds.org.  &#039;&#039;&#039;MarkLogic&#039;&#039;&#039; indexes the documents in each folder and its subfolders. This makes it fast and easy to retrieve any or all documents in any folder and/or its subfolders.&lt;br /&gt;
**Few NoSQL databases use the URI as the primary key for their documents or data. They also don&#039;t index the URI hierarchically to filter documents by folder and subfolder.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Hypertext:&#039;&#039;&#039; A document should contain data that represents the resource. The data should be &#039;&#039;&#039;human readable and self-documenting&#039;&#039;&#039;, like JSON, XML, RDF, and HTML. It should be &#039;&#039;&#039;linked data&#039;&#039;&#039; (i.e. the &amp;quot;hyper&amp;quot; in &amp;quot;hypertext&amp;quot;). A document should contain &#039;&#039;&#039; metadata links&#039;&#039;&#039; about the resource, such as RDF. It should contain &#039;&#039;&#039;action links&#039;&#039;&#039; to define what further actions can be done with the resource. It should contain &#039;&#039;&#039;related links&#039;&#039;&#039; to related resources, such as images, audio, video, related documents, etc. Each related link should define what actions can be done with the referenced resource, such as download it, display a link to it, execute a command against it, etc.)&lt;br /&gt;
**&#039;&#039;&#039;Hypertext&#039;&#039;&#039; or &#039;&#039;&#039;hypermedia&#039;&#039;&#039; documents must have all these features. Hyperlinks are what the &amp;quot;hyper&amp;quot; in hypertext and hypermedia refers to.  You can&#039;t have REST without &#039;&#039;metadata links&#039;&#039; to define what the data means, &#039;&#039;action links&#039;&#039; to know how to work with the resource, and &#039;&#039;related links&#039;&#039; to connect resources. It should all be human readable and self-documenting so a developer does not have to read documentation to know how to interact with a REST web service and its documents. &lt;br /&gt;
** &#039;&#039;&#039;MarkLogic&#039;&#039;&#039; meets all the requirements for hypertext representation. It is designed around MIME types, URIs, and Linked data.  It stores documents with their MIME types as [http://www.w3schools.com/json/ JSON], [http://www.w3schools.com/xml/ XML], [http://www.w3schools.com/webservices/ws_rdf_intro.asp RDF], [http://www.w3schools.com/html/ HTML], etc.  These documents are human-readable and self-documenting, which MarkLogic leverages to recognize and index each document&#039;s data, data structure, metadata links, action links, and related links. This makes it easy to &#039;&#039;&#039;search&#039;&#039;&#039;, &#039;&#039;&#039;query&#039;&#039;&#039;, &#039;&#039;&#039;transform&#039;&#039;&#039;, and &#039;&#039;&#039;deliver&#039;&#039;&#039; hypertext documents.  MarkLogic can also store any type of binary document and deliver it as a related resource, such as an image, video, or audio. MarkLogic is designed to process simple links and RDF links using [http://en.wikipedia.org/wiki/SPARQL SPARQL] and [https://docs.marklogic.com/xinc XInclude]. MarkLogic can represent links in many formats:  [https://docs.marklogic.com/xp XPointer], [https://docs.marklogic.com/guide/semantics/loading#id_97709 RDF/XML], [https://docs.marklogic.com/guide/semantics/loading#id_79194 RDF/JSON], [https://docs.marklogic.com/guide/semantics/loading#id_73211 Turtle], [https://docs.marklogic.com/guide/semantics/loading#id_70596 N-Triples], [https://docs.marklogic.com/guide/semantics/loading#id_61596 N-Quads], and [https://docs.marklogic.com/guide/semantics/loading#id_74485 TriG].&lt;br /&gt;
**No other NoSQL database natively indexes and fully processes all the document types required for REST hypertext: JSON, XML, RDF, HTML, CSS, and JavaScript.&lt;br /&gt;
&lt;br /&gt;
=== &#039;&#039;&#039;State and MarkLogic&#039;&#039;&#039; === &lt;br /&gt;
* State in REST exists on the client and in server documents. It does not exist in the communications protocol or in the server as cached session data. &lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Server:&#039;&#039;&#039; All information needed to process a request must be presented in the request and processed against documents in the database. State must only be in the request and in database documents: state cannot be anywhere else, such as in a session cache. The documents in the server define the state of the server. A REST server should explicitly create a state machine that defines the acceptable actions that can transacted against documents in specific contexts.&lt;br /&gt;
**A REST transaction occurs at a &#039;&#039;&#039;point in time&#039;&#039;&#039;. The state of the data in the request is unchanging, but the state of the documents and state machines in the database are often changing. Since request state and database state are both required to process the request and since shifting state creates unpredictable results, a REST transaction should run at a point in time with unchanging state. Only an ACID-compliant database can ensure consistent state because it isolates each transaction from every other transaction. The only time REST does not need an ACID-compliant database is when database documents do not change, database state machines do not change, or when clients can live with the resultant level of unreliable and unpredictable results.&lt;br /&gt;
**&#039;&#039;&#039;MarkLogic&#039;&#039;&#039; meets all the requirements for REST state.  Its web services are stateless: there is no session cache. It is ACID compliant. It ensures each transaction occurs at a point in time and is isolated from all other transactions. This ensures consistent processing during a transaction -- even across billions of documents. MarkLogic is an [http://en.wikipedia.org/wiki/Multiversion_concurrency_control MVCC] database which provides transaction isolation without slowing the performance of reads -- even when documents being read are being modified simultaneously by other transactions. (Also, like any other ACID database, when multiple updates and deletes compete for the same documents, they will impact each other&#039;s performance because change has to be serialized.)  &lt;br /&gt;
** Most other NoSQL databases are not ACID compliant. They are only suitable for REST services when their documents or data do not change or when the rate of change is slow enough or dispersed enough that it creates an acceptable level of unreliability and unpredictability.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Client:&#039;&#039;&#039; A REST client, such as a web browser or spider, locally maintains transactional state, such as what to do in response to documents and result codes that are returned from server transactions. An application exists only in the client -- not in the server (although, a server may deliver application code to a client, such as when a web server downloads HTML, CSS, and JavaScript to a browser). Client application code decides when to execute web service calls and it ties the results together to accomplish its purpose. This allows multiple authorized applications to reuse web services for a variety of purposes.  &lt;br /&gt;
**The server helps the client know what web service calls are available by providing action links with each response.  Action links are contextual and the context is based on the application account, user account, database documents, links within and between documents, the server state machine, etc. Through action links, the server can inform a client application what web service calls are permissible in any given context.&lt;br /&gt;
**&#039;&#039;&#039;MarkLogic&#039;&#039;&#039; meets the needs of client applications through its built-in ability to process and send action links to clients based on context. MarkLogic supports RDF triples and SPARQL, which enables context to be defined across applications, users, document state, links between documents, server state machine, etc. MarkLogic processes triples very quickly, which enables context to scale to billions of documents, millions of users, etc.&lt;br /&gt;
**&#039;&#039;&#039;MarkLogic&#039;&#039;&#039; also uses application and user permissions to filter which documents are returned to clients.  MarkLogic does this automatically and transparently by adding security filtering constraints into every search and query. This ensures no account can access unauthorized documents. This is fast because all security permissions are built-into MarkLogic&#039;s indexes -- which allows document-level security to scale across billions of documents.&lt;br /&gt;
** Most other NoSQL databases do not provide government-grade, document-level security and they also do not support RDF triples and SPARQL.&lt;br /&gt;
&lt;br /&gt;
Because MarkLogic can provide both the web service and database in one server, it is easy to use the state of the documents and the &lt;br /&gt;
&lt;br /&gt;
=== &#039;&#039;&#039;Transfer and MarkLogic&#039;&#039;&#039; === &lt;br /&gt;
* &#039;&#039;&#039;Transfer&#039;&#039;&#039; in REST is a communication protocol that enables a client to send a hypertext request to a server and receive back a hypertext response. The transfer must be stateless and be a request/response protocol. It must have human readable, self-descriptive headers.  The header must contain metadata about the request, such as the requested resource URI, MIME type of the resource, action to perform on the resource (such as get, put, post, patch, and delete). [http://www.w3schools.com/tags/ref_httpmethods.asp &#039;&#039;&#039;HTTP&#039;&#039;&#039;] (Hypertext transfer protocol) and &#039;&#039;&#039;HTTPS&#039;&#039;&#039; (secure HTTP) are designed specifically for REST (that is why they have &amp;quot;hypertext&amp;quot; in their name).&lt;br /&gt;
&lt;br /&gt;
* All &#039;&#039;&#039;MarkLogic&#039;&#039;&#039; communication is through through HTTP and HTTPS REST services (except for its SQL JDBC feature). This includes all internal cluster communication.  MarkLogic provides out-of-the-box REST interfaces for manipulating resources (insert, update, delete, query, search, transform, etc.) and administering MarkLogic (REST app servers, databases, indexes, clusters, etc).  MarkLogic makes it very easy to create custom REST services because everything in MarkLogic is built around REST and because they provide simple and powerful application server APIs.&lt;br /&gt;
&lt;br /&gt;
== MarkLogic Links ==&lt;br /&gt;
*[[MarkLogic]]&lt;br /&gt;
*[[MarkLogic Query and Search]]&lt;br /&gt;
*[[MarkLogic Training Resources]]&lt;br /&gt;
*[[Installing MarkLogic]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[Category: MarkLogic]]&lt;/div&gt;</summary>
		<author><name>Bowersmt</name></author>
	</entry>
	<entry>
		<id>https://tech.churchofjesuschrist.org/wiki/index.php?title=What_is_MarkLogic%3F&amp;diff=70563</id>
		<title>What is MarkLogic?</title>
		<link rel="alternate" type="text/html" href="https://tech.churchofjesuschrist.org/wiki/index.php?title=What_is_MarkLogic%3F&amp;diff=70563"/>
		<updated>2014-11-14T08:44:57Z</updated>

		<summary type="html">&lt;p&gt;Bowersmt: Added links and removed search&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;br /&gt;
== What is MarkLogic? ==&lt;br /&gt;
[http://www.marklogic.com/what-is-marklogic/ MarkLogic] is a [http://www.marklogic.com/what-is-marklogic/inside-marklogic/ &#039;&#039;&#039;REST application server&#039;&#039;&#039;, &#039;&#039;&#039;document database&#039;&#039;&#039;, and &#039;&#039;&#039;search engine&#039;&#039;&#039;]. It is REST through and through. It is built specifically for hypertext documents, links, metadata, URIs, MIME types, and HTTP. It is schema-agnostic because it is automatically aware of the independent structure of each of its JSON and XML documents. It is search-centric because it can search for &#039;&#039;any combination&#039;&#039; of words, values, structures, and links within and across documents. It scales horizontally to hundreds of servers within and between data centers while maintaining ACID-compliant transactions. &lt;br /&gt;
&lt;br /&gt;
MarkLogic has the following [http://www.marklogic.com/what-is-marklogic/enterprise-nosql/ enterprise features]:&lt;br /&gt;
* [http://www.marklogic.com/resources/java-developers-guide/ Java APIs]&lt;br /&gt;
* [http://en.wikipedia.org/wiki/Node.js Node.js APIs]&lt;br /&gt;
* [http://developer.marklogic.com/learn/2009-07-search-api-walkthrough Search] and [http://developer.marklogic.com/learn/arch/search-and-indexing Query]&lt;br /&gt;
* [http://www.marklogic.com/blog/can-you-pass-the-acid-test/ ACID Transactions]&lt;br /&gt;
* [http://www.marklogic.com/resources/marklogic-high-availability-and-disaster-recovery/resource_download/datasheets/ High Availability] and [http://docs.marklogic.com/guide/database-replication/dbrep_intro#chapter Disaster Recovery]&lt;br /&gt;
* [http://www.marklogic.com/resources/marklogic-flexible-replication/resource_download/datasheets/ Replication within and across data centers]&lt;br /&gt;
* [http://docs.marklogic.com/guide/admin/security#chapter Government-grade Security]&lt;br /&gt;
* [https://docs.marklogic.com/guide/cluster.pdf Scalability] and [https://docs.marklogic.com/guide/admin/database-rebalancing#chapter Elasticity]&lt;br /&gt;
* [https://docs.marklogic.com/guide/ec2/managing#chapter On-premise or Cloud Deployment (especially AWS)]&lt;br /&gt;
* [http://www.marklogic.com/resources/marklogic-and-hadoop/resource_download/datasheets/ Hadoop for Storage and Compute]&lt;br /&gt;
* [http://www.marklogic.com/resources/marklogic-semantics-mlw14/ Semantics]&lt;br /&gt;
&lt;br /&gt;
== What is REST? ==&lt;br /&gt;
REST is an architectural style that uses a uniform resource identifier (&#039;&#039;&#039;URI&#039;&#039;&#039;) and a web protocol (&#039;&#039;&#039;HTTP/HTTPS&#039;&#039;&#039;) to request and transfer a representation (&#039;&#039;&#039;MIME media type&#039;&#039;&#039;) of the state of a resource (&#039;&#039;&#039;document&#039;&#039;&#039;) at a point in time from a server to a client. &lt;br /&gt;
&lt;br /&gt;
REST was coined and defined by Roy Fielding in his &lt;br /&gt;
[http://www.ics.uci.edu/~fielding/pubs/dissertation/top.htm dissertation, &#039;&#039;Architectural Styles and the Design of Network-based Software Architectures&#039;&#039;].  REST standardizes and documents the patterns used in the world wide web: self-documenting hypertext with data and metadata (HTML), stateless request/response communication protocol (HTTP/HTTPS), resource locators (URL), multiple representations per URL (MIME types), and downloading code on demand to process resources (JavaScript, CSS, etc.).&lt;br /&gt;
&lt;br /&gt;
REST consists of three main concepts: &lt;br /&gt;
* (RE) Representation&lt;br /&gt;
* (S)  State &lt;br /&gt;
* (T)  Transfer &lt;br /&gt;
&lt;br /&gt;
== Why is MarkLogic RESTful? ==&lt;br /&gt;
&lt;br /&gt;
=== &#039;&#039;&#039;Representation and MarkLogic&#039;&#039;&#039; === &lt;br /&gt;
* A representation is a document that represents a resource. It has three requirements: MIME media type, URI, and hypertext.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;MIME type:&#039;&#039;&#039; Each resource can be represented by one or more types of documents. The MIME media type defines the representation a client requests. A client may request the resource to be represented as JSON, XML, HTML, PNG, PDF, etc. &lt;br /&gt;
**&#039;&#039;&#039;MarkLogic&#039;&#039;&#039; stores any type of document and assigns the appropriate [http://developer.marklogic.com/blog/document-formats-part2 MIME type] to it. It can fully index, query, search, and process JSON, XML, and RDF documents. It meets the REST requirement of being able to transform JSON, XML, and RDF documents into any other MIME type. It knows how to execute JavaScript, XQuery, XSLT, and SPARQL documents. It knows how [http://docs.marklogic.com/guide/cpf/default#chapter to transform into XHTML] the content, formatting, and structure of Microsoft Word, PowerPoint, Excel, textual PDF, DocBook, and CSS  documents. (It can also use Microsoft Office to create, edit, and manage content in MarkLogic.) It knows how to [https://docs.marklogic.com/guide/search-dev/binary-document-metadata extract metadata and text from over 138 types of binary documents], such as raster images, vector images, videos, archive files, database files, encoded emails, presentations, spreadsheets, word-processing documents, text formats. &lt;br /&gt;
**Few NoSQL databases use MIME types to identify the media type of each document.  Most NoSQL databases support only one type of data and it is usually proprietary: columnar, BSON, binary, etc. Most cannot transform from one MIME type to another.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;URI:&#039;&#039;&#039; A resource is identified by a globally unique identifier (URI). &#039;&#039;&#039;MarkLogic&#039;&#039;&#039; identifies each document with a [http://developer.marklogic.com/try/rest/page2 unique URI]. A document in MarkLogic is like a row in a table in a schema in a relational database. A URI is liberating. It provides random access to any resource anywhere. It is like being able to retrieve any row in any table in any schema of a relational database without having to know what table and schema the row is stored in.  &lt;br /&gt;
**Navigating URL hierarchy is fundamental to REST. MarkLogic understands the hierarchy within a URI, which is represented by slashes &amp;quot;/&amp;quot;, such as https://www.lds.org/scriptures/ot/gen/1  MarkLogic treats the items between the slashes as folders. The URI of each document automatically places it in a folder in a folder hierarchy. A URI automatically defines the folder hierarchy.  In the example URI above, the document for Genesis chapter 1, is located in the Genesis folder, which is located in the Old Testament folder, which is located in the Scriptures folder on lds.org.  &#039;&#039;&#039;MarkLogic&#039;&#039;&#039; indexes the documents in each folder and its subfolders. This makes it fast and easy to retrieve any or all documents in any folder and/or its subfolders.&lt;br /&gt;
**Few NoSQL databases use the URI as the primary key for their documents or data. They also don&#039;t index the URI hierarchically to filter documents by folder and subfolder.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Hypertext:&#039;&#039;&#039; A document should contain data that represents the resource. The data should be &#039;&#039;&#039;human readable and self-documenting&#039;&#039;&#039;, like JSON, XML, RDF, and HTML. It should be &#039;&#039;&#039;linked data&#039;&#039;&#039; (i.e. the &amp;quot;hyper&amp;quot; in &amp;quot;hypertext&amp;quot;). A document should contain &#039;&#039;&#039; metadata links&#039;&#039;&#039; about the resource, such as RDF. It should contain &#039;&#039;&#039;action links&#039;&#039;&#039; to define what further actions can be done with the resource. It should contain &#039;&#039;&#039;related links&#039;&#039;&#039; to related resources, such as images, audio, video, related documents, etc. Each related link should define what actions can be done with the referenced resource, such as download it, display a link to it, execute a command against it, etc.)&lt;br /&gt;
**&#039;&#039;&#039;Hypertext&#039;&#039;&#039; or &#039;&#039;&#039;hypermedia&#039;&#039;&#039; documents must have all these features. Hyperlinks are what the &amp;quot;hyper&amp;quot; in hypertext and hypermedia refers to.  You can&#039;t have REST without &#039;&#039;metadata links&#039;&#039; to define what the data means, &#039;&#039;action links&#039;&#039; to know how to work with the resource, and &#039;&#039;related links&#039;&#039; to connect resources. It should all be human readable and self-documenting so a developer does not have to read documentation to know how to interact with a REST web service and its documents. &lt;br /&gt;
** &#039;&#039;&#039;MarkLogic&#039;&#039;&#039; meets all the requirements for hypertext representation. It is designed around MIME types, URIs, and Linked data.  It stores documents with their MIME types as [http://www.w3schools.com/json/ JSON], [http://www.w3schools.com/xml/ XML], [http://www.w3schools.com/webservices/ws_rdf_intro.asp RDF], [http://www.w3schools.com/html/ HTML], etc.  These documents are human-readable and self-documenting, which MarkLogic leverages to recognize and index each document&#039;s data, data structure, metadata links, action links, and related links. This makes it easy to &#039;&#039;&#039;search&#039;&#039;&#039;, &#039;&#039;&#039;query&#039;&#039;&#039;, &#039;&#039;&#039;transform&#039;&#039;&#039;, and &#039;&#039;&#039;deliver&#039;&#039;&#039; hypertext documents.  MarkLogic can also store any type of binary document and deliver it as a related resource, such as an image, video, or audio. MarkLogic is designed to process simple links and RDF links using [http://en.wikipedia.org/wiki/SPARQL SPARQL] and [https://docs.marklogic.com/xinc XInclude]. MarkLogic can represent links in many formats:  [https://docs.marklogic.com/xp XPointer], [https://docs.marklogic.com/guide/semantics/loading#id_97709 RDF/XML], [https://docs.marklogic.com/guide/semantics/loading#id_79194 RDF/JSON], [https://docs.marklogic.com/guide/semantics/loading#id_73211 Turtle], [https://docs.marklogic.com/guide/semantics/loading#id_70596 N-Triples], [https://docs.marklogic.com/guide/semantics/loading#id_61596 N-Quads], and [https://docs.marklogic.com/guide/semantics/loading#id_74485 TriG].&lt;br /&gt;
**No other NoSQL database natively indexes and fully processes all the document types required for REST hypertext: JSON, XML, RDF, HTML, CSS, and JavaScript.&lt;br /&gt;
&lt;br /&gt;
=== &#039;&#039;&#039;State and MarkLogic&#039;&#039;&#039; === &lt;br /&gt;
* State in REST exists on the client and in server documents. It does not exist in the communications protocol or in the server as cached session data. &lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Server:&#039;&#039;&#039; All information needed to process a request must be presented in the request and processed against documents in the database. State must only be in the request and in database documents: state cannot be anywhere else, such as in a session cache. The documents in the server define the state of the server. A REST server should explicitly create a state machine that defines the acceptable actions that can transacted against documents in specific contexts.&lt;br /&gt;
**A REST transaction occurs at a &#039;&#039;&#039;point in time&#039;&#039;&#039;. The state of the data in the request is unchanging, but the state of the documents and state machines in the database are often changing. Since request state and database state are both required to process the request and since shifting state creates unpredictable results, a REST transaction should run at a point in time with unchanging state. Only an ACID-compliant database can ensure consistent state because it isolates each transaction from every other transaction. The only time REST does not need an ACID-compliant database is when database documents do not change, database state machines do not change, or when clients can live with the resultant level of unreliable and unpredictable results.&lt;br /&gt;
**&#039;&#039;&#039;MarkLogic&#039;&#039;&#039; meets all the requirements for REST state.  Its web services are stateless: there is no session cache. It is ACID compliant. It ensures each transaction occurs at a point in time and is isolated from all other transactions. This ensures consistent processing during a transaction -- even across billions of documents. MarkLogic is an [http://en.wikipedia.org/wiki/Multiversion_concurrency_control MVCC] database which provides transaction isolation without slowing the performance of reads -- even when documents being read are being modified simultaneously by other transactions. (Also, like any other ACID database, when multiple updates and deletes compete for the same documents, they will impact each other&#039;s performance because change has to be serialized.)  &lt;br /&gt;
** Most other NoSQL databases are not ACID compliant. They are only suitable for REST services when their documents or data do not change or when the rate of change is slow enough or dispersed enough that it creates an acceptable level of unreliability and unpredictability.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Client:&#039;&#039;&#039; A REST client, such as a web browser or spider, locally maintains transactional state, such as what to do in response to documents and result codes that are returned from server transactions. An application exists only in the client -- not in the server (although, a server may deliver application code to a client, such as when a web server downloads HTML, CSS, and JavaScript to a browser). Client application code decides when to execute web service calls and it ties the results together to accomplish its purpose. This allows multiple authorized applications to reuse web services for a variety of purposes.  &lt;br /&gt;
**The server helps the client know what web service calls are available by providing action links with each response.  Action links are contextual and the context is based on the application account, user account, database documents, links within and between documents, the server state machine, etc. Through action links, the server can inform a client application what web service calls are permissible in any given context.&lt;br /&gt;
**&#039;&#039;&#039;MarkLogic&#039;&#039;&#039; meets the needs of client applications through its built-in ability to process and send action links to clients based on context. MarkLogic supports RDF triples and SPARQL, which enables context to be defined across applications, users, document state, links between documents, server state machine, etc. MarkLogic processes triples very quickly, which enables context to scale to billions of documents, millions of users, etc.&lt;br /&gt;
**&#039;&#039;&#039;MarkLogic&#039;&#039;&#039; also uses application and user permissions to filter which documents are returned to clients.  MarkLogic does this automatically and transparently by adding security filtering constraints into every search and query. This ensures no account can access unauthorized documents. This is fast because all security permissions are built-into MarkLogic&#039;s indexes -- which allows document-level security to scale across billions of documents.&lt;br /&gt;
** Most other NoSQL databases do not provide government-grade, document-level security and they also do not support RDF triples and SPARQL.&lt;br /&gt;
&lt;br /&gt;
Because MarkLogic can provide both the web service and database in one server, it is easy to use the state of the documents and the &lt;br /&gt;
&lt;br /&gt;
=== &#039;&#039;&#039;Transfer and MarkLogic&#039;&#039;&#039; === &lt;br /&gt;
* &#039;&#039;&#039;Transfer&#039;&#039;&#039; in REST is a communication protocol that enables a client to send a hypertext request to a server and receive back a hypertext response. The transfer must be stateless and be a request/response protocol. It must have human readable, self-descriptive headers.  The header must contain metadata about the request, such as the requested resource URI, MIME type of the resource, action to perform on the resource (such as get, put, post, patch, and delete). [http://www.w3schools.com/tags/ref_httpmethods.asp &#039;&#039;&#039;HTTP&#039;&#039;&#039;] (Hypertext transfer protocol) and &#039;&#039;&#039;HTTPS&#039;&#039;&#039; (secure HTTP) are designed specifically for REST (that is why they have &amp;quot;hypertext&amp;quot; in their name).&lt;br /&gt;
&lt;br /&gt;
* All &#039;&#039;&#039;MarkLogic&#039;&#039;&#039; communication is through through HTTP and HTTPS REST services (except for its SQL JDBC feature). This includes all internal cluster communication.  MarkLogic provides out-of-the-box REST interfaces for manipulating resources (insert, update, delete, query, search, transform, etc.) and administering MarkLogic (REST app servers, databases, indexes, clusters, etc).  MarkLogic makes it very easy to create custom REST services because everything in MarkLogic is built around REST and because they provide simple and powerful application server APIs.&lt;br /&gt;
&lt;br /&gt;
== MarkLogic Links ==&lt;br /&gt;
*[[MarkLogic]]&lt;br /&gt;
*[[MarkLogic Query and Search]]&lt;br /&gt;
*[[MarkLogic Training Resources]]&lt;br /&gt;
*[[Installing MarkLogic]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[Category: MarkLogic]]&lt;/div&gt;</summary>
		<author><name>Bowersmt</name></author>
	</entry>
	<entry>
		<id>https://tech.churchofjesuschrist.org/wiki/index.php?title=MarkLogic&amp;diff=70562</id>
		<title>MarkLogic</title>
		<link rel="alternate" type="text/html" href="https://tech.churchofjesuschrist.org/wiki/index.php?title=MarkLogic&amp;diff=70562"/>
		<updated>2014-11-14T08:41:04Z</updated>

		<summary type="html">&lt;p&gt;Bowersmt: Adding headings&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== MarkLogic Landing Page ==&lt;br /&gt;
This is the MarkLogic home page.  MarkLogic is an all-in-one application server, document database, and search engine.  It is entirely based on REST. For an extensive explanation of what MarkLogic is and what it can do, see [[What is MarkLogic?]]&lt;br /&gt;
&lt;br /&gt;
== Requesting a MarkLogic License == &lt;br /&gt;
Employees of the Church may request a license key by emailing [mailto:DL-ICS-MARKLOGIC DL-ICS-MARKLOGIC]. Members of the community may also install a local copy of MarkLogic but must request a [http://developer.marklogic.com/free-developer developer license key from MarkLogic].&lt;br /&gt;
&lt;br /&gt;
== Links to other MarkLogic Documents ==&lt;br /&gt;
* [[What is MarkLogic?]]&lt;br /&gt;
* [[MarkLogic Query and Search]]&lt;br /&gt;
* [[Installing MarkLogic]]&lt;br /&gt;
* [[MarkLogic Training Resources]]&lt;br /&gt;
&lt;br /&gt;
[[Category: MarkLogic]]&lt;/div&gt;</summary>
		<author><name>Bowersmt</name></author>
	</entry>
	<entry>
		<id>https://tech.churchofjesuschrist.org/wiki/index.php?title=MarkLogic&amp;diff=70561</id>
		<title>MarkLogic</title>
		<link rel="alternate" type="text/html" href="https://tech.churchofjesuschrist.org/wiki/index.php?title=MarkLogic&amp;diff=70561"/>
		<updated>2014-11-14T08:39:31Z</updated>

		<summary type="html">&lt;p&gt;Bowersmt: Added more information on getting a licence key&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== MarkLogic ==&lt;br /&gt;
This is the landing page for MarkLogic.  MarkLogic is an all-in-one application server, document database, and search engine.  It is entirely based on REST. For an extensive explanation of what MarkLogic is and what it can do, see [[What is MarkLogic?]]&lt;br /&gt;
&lt;br /&gt;
Employees of the Church may request a license key by emailing [mailto:DL-ICS-MARKLOGIC DL-ICS-MARKLOGIC]. Members of the community may also install a local copy of MarkLogic but must request a [http://developer.marklogic.com/free-developer developer license key from MarkLogic].&lt;br /&gt;
&lt;br /&gt;
== Links to other MarkLogic Documents ==&lt;br /&gt;
* [[What is MarkLogic?]]&lt;br /&gt;
* [[MarkLogic Query and Search]]&lt;br /&gt;
* [[Installing MarkLogic]]&lt;br /&gt;
* [[MarkLogic Training Resources]]&lt;br /&gt;
&lt;br /&gt;
[[Category: MarkLogic]]&lt;/div&gt;</summary>
		<author><name>Bowersmt</name></author>
	</entry>
	<entry>
		<id>https://tech.churchofjesuschrist.org/wiki/index.php?title=MarkLogic&amp;diff=70556</id>
		<title>MarkLogic</title>
		<link rel="alternate" type="text/html" href="https://tech.churchofjesuschrist.org/wiki/index.php?title=MarkLogic&amp;diff=70556"/>
		<updated>2014-11-14T08:25:09Z</updated>

		<summary type="html">&lt;p&gt;Bowersmt: Updated links&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== MarkLogic ==&lt;br /&gt;
This is the landing page for MarkLogic.  MarkLogic is an all-in-one application server, document database, and search engine.  It is entirely based on REST. For an extensive explanation of what MarkLogic is and what it can do, see [[What is MarkLogic?]]&lt;br /&gt;
&lt;br /&gt;
== Links to other MarkLogic Documents ==&lt;br /&gt;
* [[What is MarkLogic?]]&lt;br /&gt;
* [[MarkLogic Query and Search]]&lt;br /&gt;
* [[Installing MarkLogic]]&lt;br /&gt;
* [[MarkLogic Training Resources]]&lt;br /&gt;
&lt;br /&gt;
[[Category: MarkLogic]]&lt;/div&gt;</summary>
		<author><name>Bowersmt</name></author>
	</entry>
	<entry>
		<id>https://tech.churchofjesuschrist.org/wiki/index.php?title=MarkLogic_Query_and_Search&amp;diff=70555</id>
		<title>MarkLogic Query and Search</title>
		<link rel="alternate" type="text/html" href="https://tech.churchofjesuschrist.org/wiki/index.php?title=MarkLogic_Query_and_Search&amp;diff=70555"/>
		<updated>2014-11-14T08:24:04Z</updated>

		<summary type="html">&lt;p&gt;Bowersmt: Changed Category&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== MarkLogic Query and Search ==&lt;br /&gt;
Indexes are central to everything you do in MarkLogic.  They are central to how MarkLogic stores data, scales massively, and processes data quickly. They are central to how you develop because you have to use MarkLogic&#039;s indexes to query and search documents. You have to understand how MarkLogic&#039;s indexes work to be able to create fast queries. And you have to know how to model document structure to work best with indexes.&lt;br /&gt;
&lt;br /&gt;
=== How does MarkLogic compare to a relational database? ===&lt;br /&gt;
A document in MarkLogic is very much like a row in a relational database, and a document type ties documents together like a table ties rows together. Both use indexes to resolve queries without having to scan through rows or documents.&lt;br /&gt;
&lt;br /&gt;
Unlike relational databases, MarkLogic can&#039;t do full table scans; queries must use indexes. In contrast, relational databases often use a full table scan to retrieve every row in a table. A rule of thumb in relational databases is that it is faster to directly read in &#039;&#039;all&#039;&#039; the rows when a query accesses more than roughly 25% of the rows. This is because relational databases use variations of the B-Tree index, which requires 3-4 random IOs to find one row and 1 IO to retrieve the row: this is 4-5 total IOs per row.  B-Tree indexes work best for single row lookups, but they become increasingly costly the more rows they retrieve. If an index has to lookup 25% of its rows with 4 IOs per row, the database will do the same amount of IO if it reads in all of the rows (1 IO per row). Since sequential IO on disks is faster than random IO, relational databases prefer full table scans when accessing more than about 25% of rows in a table. On analytical data warehouses, full table scans are always preferred.  &lt;br /&gt;
&lt;br /&gt;
In addition, a relational database [https://docs.oracle.com/database/121/TGSQL/tgsql_optop.htm#TGSQL234 often directly scans through index data] rather than stepping through its B-Tree structure. Databases use a variety of index scans: full scans, range scans, skip scans, join scans, etc. This is index and table records are stored sequentially on disk. This often makes it faster to take advantage of the speed of sequential disk IO and directly load all index or table rows into RAM and process them in RAM; as opposed to walking a b-tree structure and doing multiple slow random IOs to retrieve each record. For the same reason, row and index scans work well in columnar NoSQL databases.&lt;br /&gt;
&lt;br /&gt;
=== Why do MarkLogic queries have to use Indexes? ===&lt;br /&gt;
To maximize parallelism and to spread processing throughout a cluster, MarkLogic spreads documents across the cluster. MarkLogic automatically creates multiple shards per server and spreads them across all the servers in the cluster. Documents are placed in a shard in the order they are created or modified; thus, documents of all types may be randomly intermixed in a shard. Since a shard is not organized by document type, doing a sequential scan to resolve a query would require retrieving and processing all documents in the database. Full scans are not practical in MarkLogic. All queries and searches need to use indexes. For this reason, MarkLogic automatically indexes almost everything. You can also create additional specialized indexes.  MarkLogic indexes are not B-Tree indexes; they are designed to be sharded and queried in parallel across stands, forests, and a database cluster that spans many servers.&lt;br /&gt;
&lt;br /&gt;
=== How does MarkLogic scale horizontally? ===&lt;br /&gt;
Documents in MarkLogic belong to a database. Within a database are one or more servers.  Each server may contain zero or more &amp;quot;forests&amp;quot;. Within each forest are one or more &amp;quot;stands&amp;quot;. Within each stand are one or more &amp;quot;trees&amp;quot;. A document is hierarchical so it is called a &amp;quot;tree&amp;quot;.  (MarkLogic uses the terms &amp;quot;stand&amp;quot; and &amp;quot;forest&amp;quot; instead of &amp;quot;shard&amp;quot;, but they have the same meaning.) &lt;br /&gt;
&lt;br /&gt;
A client contacts one of the servers in a MarkLogic cluster and initiates a query or search. Because MarkLogic communicates through REST web services, a load balancer can spread requests across the servers in a MarkLogic cluster.  The initiating server does the following&lt;br /&gt;
#it validates the query request from the client&lt;br /&gt;
#it parses and optimizes the query &lt;br /&gt;
#it sends the query to all servers that have forests in the database&lt;br /&gt;
##each server sends it to its forests &lt;br /&gt;
##each forest sends it to each stand &lt;br /&gt;
##each stand uses its indexes to find matching documents&lt;br /&gt;
###all stands and forests query the indexes in parallel&lt;br /&gt;
##forests combine the matching document IDs from all their stands&lt;br /&gt;
##forests sort the matching document IDs (in relevance score order or value order)&lt;br /&gt;
##when complete, each forest returns a sorted iterator to the initiating server&lt;br /&gt;
#when each forest has returned an iterator&lt;br /&gt;
#it walks the sorted iterators from all the forests and combines the results in sorted &lt;br /&gt;
#it retrieves matching documents from its &#039;&#039;Expanded Tree Cache&#039;&#039; or from the forests when documents are not cached&lt;br /&gt;
##forests retrieve documents from their &#039;&#039;Compressed Tree Cache&#039;&#039; or from disk when documents are not cached&lt;br /&gt;
#it filters returned documents to remove false positive matches &lt;br /&gt;
#it optionally transforms documents &lt;br /&gt;
##it creates new documents by extracting matching elements, changing structure, changing file format, etc.&lt;br /&gt;
#it returns all matching (optionally transformed) documents to the requester&lt;br /&gt;
#it saves resulting document IDs when paging query results, so it can return subsequent pages of matching documents in subsequent requests&lt;br /&gt;
&lt;br /&gt;
The initiating server&#039;s process is CPU intensive, serialized, and blocks while waiting on forests. To prevent this from being a bottleneck to the cluster, you can dedicate nodes in the cluster to do nothing but evaluate queries. These are called e-nodes (evaluation nodes). These nodes don&#039;t hold data. If they held data, the &#039;&#039;serialized&#039;&#039; evaluation process would compete with the &#039;&#039;parallel&#039;&#039; index matching process.  Instead e-nodes are dedicated to validating, parsing, sorting, filtering, transforming, and paginating documents. They cache documents in the &#039;&#039;Expanded Tree Cache&#039;&#039; to minimize the number of documents they have to retrieve from data nodes (d-nodes). D-nodes only do parallel index processing and sorting. They cache documents in their &#039;&#039;Compressed Tree Cache&#039;&#039; to reduce disk IO. &lt;br /&gt;
&lt;br /&gt;
=== How do you optimize a MarkLogic cluster to run queries faster? ===&lt;br /&gt;
*E-nodes and d-nodes can be scaled independently to match the load. &lt;br /&gt;
*You can optimize an e-node by minimizing its &#039;&#039;Compressed Tree Cache&#039;&#039; and maximizing its &#039;&#039;Expanded Tree Cache&#039;&#039;. An e-node needs a big &#039;&#039;Expanded Tree Cache&#039;&#039; so it doesn&#039;t have to retrieve as many documents from d-nodes. An e-node doesn&#039;t need a &#039;&#039;Compressed Tree Cache&#039;&#039; because it doesn&#039;t have any data.&lt;br /&gt;
*You can optimize a d-node by doing the opposite of the e-node: maximize the &#039;&#039;Compressed Tree Cache&#039;&#039; and minimize the &#039;&#039;Expanded Tree Cache&#039;&#039;. You can also optimize d-nodes by making sure each d-node runs on similar hardware and that each forest has a similar number of documents. This is important because all forests process queries in parallel and the slowest forest holds up each query: e-nodes have to wait until the slowest forest finishes.&lt;br /&gt;
*You can optimize a query by making it unfiltered.&lt;br /&gt;
**This means it is completely resolved by the indexes. Because no filtering is required, the initiating server doesn&#039;t have to verify that documents match.&lt;br /&gt;
*You can optimize a query by eliminating false positives.  &lt;br /&gt;
**False positives occur when a query identifies a possible match for a document, but it cannot prove it is a match until the filtering process opens the document and verifies it. &lt;br /&gt;
**False positives happen because MarkLogic only partially indexes certain document items. MarkLogic cannot index everything because it would take too much time and space. For example, MarkLogic has a structure index. It indexes relationships between elements in a document.  MarkLogic cannot afford to index each element&#039;s path from itself to every other element. MarkLogic compromises on indexing only parent/child relationships. This is effective in eliminating most non-matching documents, but it can produce false positives.  The only way to know if a document is an &#039;&#039;exact&#039;&#039; match, MarkLogic must open the document and verify it.&lt;br /&gt;
**For example, suppose a query searches for the following path: &amp;lt;br&amp;gt;&amp;lt;code&amp;gt;books/poetry/poem&amp;lt;/code&amp;gt;&amp;lt;br&amp;gt; The structure index will match documents containing books/poetry and poetry/poem. The resulting documents are a probable match, but could contain false positives, such as &amp;lt;br&amp;gt;&amp;lt;code&amp;gt;books/poetry/fantasy/poetry/poem&amp;lt;/code&amp;gt;.&lt;br /&gt;
**You can eliminate false positive structures queries by giving elements unique names. They are  unique no matter where in they are in the structure and they are more self-descriptive.  Instead of naming an element &amp;quot;line&amp;quot; which can mean many things, you can use the precise name  &amp;quot;poemTextLine&amp;quot;. &lt;br /&gt;
*You can optimize a query by greatly limiting how many documents it matches. Design each query to return as few documents as possible. &lt;br /&gt;
**It is expensive to transmit documents. Matching documents have to travel from stands to forests to the initiating server, and to the requester. &lt;br /&gt;
**It is expensive to process documents on the initiating server and the requester. &lt;br /&gt;
**It takes processing time on d-nodes to compare lists of document IDs. The fewer the matching document IDs in one part of the query, the faster the entire query runs. &lt;br /&gt;
**The more matching document IDs, the more work MarkLogic has to do in a d-node to compare, union, intersect, and subract them from matching document IDs returned by other parts of the query. &lt;br /&gt;
**The more matching document IDs, the more sorting MarkLogic has to do in the stands, forests, and initiating server.&lt;br /&gt;
&lt;br /&gt;
=== How does a MarkLogic query compare to map/reduce? ===&lt;br /&gt;
A MarkLogic query or search is similar to map/reduce.  When you query or search for documents in a database, MarkLogic spreads the work across all the servers to be executed in parallel. This is like a &#039;&#039;map&#039;&#039; process because indexes filter out non-matching documents by combining term, range, and semantic indexes according to the query map. The results are then &#039;&#039;reduced&#039;&#039; at the forest level and again at the database level and again at the initiating server. This parallel division of responsibilities enables MarkLogic to scale.&lt;br /&gt;
&lt;br /&gt;
== Term, Range, and Semantic Indexes ==&lt;br /&gt;
MarkLogic indexes are not B-Tree indexes. MarkLogic uses &#039;&#039;&#039;term&#039;&#039;&#039;, &#039;&#039;&#039;range&#039;&#039;&#039;, and &#039;&#039;&#039;semantic&#039;&#039;&#039; indexes. &lt;br /&gt;
*&#039;&#039;&#039;A term index&#039;&#039;&#039; associates a term with every document that contains the term.  For example, in a word index, every word in the database is stored in the index. Associated with each word in the index is a list of each document ID that contains the term.  &lt;br /&gt;
*&#039;&#039;&#039;A range index&#039;&#039;&#039; is a double term index: it contains each term and all document IDs that contain that term, and it contains each document ID and all the terms that are in the document.&lt;br /&gt;
*&#039;&#039;&#039;A semantic index&#039;&#039;&#039; is similar to a range index but it is optimized to store triples (three pieces of data: subject, object, and predicate).&lt;br /&gt;
&lt;br /&gt;
Term indexes are fast. Give the index a term, and with one lookup, it returns &#039;&#039;all&#039;&#039; documents that contain the term. Term indexes are memory mapped files. They run in RAM unless you run out of RAM and then firmware in the CPU efficiently swaps them to and from disk. Thus, it is best to have enough RAM in a MarkLogic server to contain all indexes in memory.&lt;br /&gt;
&lt;br /&gt;
Unlike B-Tree indexes, term indexes are easily sharded within and between servers. MarkLogic takes advantage of this to run queries in parallel within and across servers. This is how MarkLogic can scale to billions of documents and still return queries and searches in milliseconds.&lt;br /&gt;
&lt;br /&gt;
When documents are inserted or updated, MarkLogic indexes them in RAM (as well as appends the changes to a journal on disk). When documents in RAM start to consume too much RAM, MarkLogic writes them to disk as a &amp;quot;stand&amp;quot; in a &amp;quot;forest&amp;quot; and starts creating a new &amp;quot;stand&amp;quot; in RAM.  &lt;br /&gt;
&lt;br /&gt;
When you query or search for documents, MarkLogic goes to the indexes in the stands (which are cached in RAM) and evaluates the query in parallel. Each stand index returns a list of document IDs (a list of numbers) that match the query. MarkLogic takes the document IDs returned by each stand and merges them into a final list of document IDs, whcih it uses to retrieve the documents from cache or disk. This works well because computers are very fast at sort merging lists of numbers.&lt;br /&gt;
&lt;br /&gt;
MarkLogic uses the same indexes for both queries and searches. This allows you to combine search and query expressions. The main difference between search and query is how documents are sorted: searches sort by relevance and queries sort by values. Another difference is that queries tend to use value indexes and searches tend to use word and phrase indexes. &lt;br /&gt;
&lt;br /&gt;
=== What specific indexes does MarkLogic have? ===&lt;br /&gt;
MarkLogic uses indexes to extract words, values, structures, and links out of documents. An index is an altered view of a document. It enables you to search and query for documents &amp;lt;br&amp;gt;&#039;&#039;&#039;as if they contained only:&#039;&#039;&#039;&lt;br /&gt;
*&#039;&#039;&#039;Words:&#039;&#039;&#039; a flat set of words without structure, such as &amp;lt;br&amp;gt;&amp;lt;code&amp;gt;[&amp;quot;Mary&amp;quot;, &amp;quot;had&amp;quot;, &amp;quot;a&amp;quot;, &amp;quot;little&amp;quot;, &amp;quot;lamb&amp;quot;]&amp;lt;/code&amp;gt;&lt;br /&gt;
*&#039;&#039;&#039;Phrases:&#039;&#039;&#039; a flat set of phrases without structure, such as &amp;lt;br&amp;gt;&amp;lt;code&amp;gt;[&amp;quot;Mary had&amp;quot;, &amp;quot;had a&amp;quot;, &amp;quot;a little&amp;quot;, &amp;quot;little lamb&amp;quot;]&amp;lt;/code&amp;gt;&lt;br /&gt;
*&#039;&#039;&#039;Elements:&#039;&#039;&#039; a flat set of elements without values, such as &amp;lt;br&amp;gt;&amp;lt;code&amp;gt;[&amp;quot;poem&amp;quot;, &amp;quot;text&amp;quot;, &amp;quot;line&amp;quot;]&amp;lt;/code&amp;gt;&lt;br /&gt;
*&#039;&#039;&#039;Element-values:&#039;&#039;&#039; a flat set of elements with string values, such as &amp;lt;br&amp;gt;&amp;lt;code&amp;gt;&amp;quot;line&amp;quot;: &amp;quot;Mary had a little lamb&amp;quot;&amp;lt;/code&amp;gt;&lt;br /&gt;
*&#039;&#039;&#039;Element-words:&#039;&#039;&#039; a flat set of elements with words, such as &amp;lt;br&amp;gt;&amp;lt;code&amp;gt;&amp;quot;line&amp;quot;: [&amp;quot;Mary&amp;quot;, &amp;quot;had&amp;quot;, &amp;quot;a&amp;quot;, &amp;quot;little&amp;quot;, &amp;quot;lamb&amp;quot;]&amp;lt;/code&amp;gt;&lt;br /&gt;
*&#039;&#039;&#039;Element-phrases:&#039;&#039;&#039; a flat set of elements with phrases, such as &amp;lt;br&amp;gt;&amp;lt;code&amp;gt;&amp;quot;line&amp;quot;: [&amp;quot;Mary had&amp;quot;, &amp;quot;had a&amp;quot;, &amp;quot;a little&amp;quot;, &amp;quot;little lamb&amp;quot;]&amp;lt;/code&amp;gt;&lt;br /&gt;
*&#039;&#039;&#039;Element-value lexicon:&#039;&#039;&#039; a flat set of elements with typed values, such as &amp;lt;br&amp;gt;&amp;lt;code&amp;gt;&amp;quot;lineSequence&amp;quot;: 3&amp;lt;/code&amp;gt;&amp;lt;br&amp;gt; or a list, count, or co-occurrence of element values scoped to a database, set of documents, or one document.&lt;br /&gt;
*&#039;&#039;&#039;XPath-structure-value lexicon:&#039;&#039;&#039; a flat set of hierarchical elements with typed values, such as &amp;lt;br&amp;gt;&amp;lt;code&amp;gt;poem.text.line.lineSequence: 3&amp;lt;/code&amp;gt;&amp;lt;br&amp;gt; or a list, count, or co-occurrence of hierarchical element values scoped to a database, set of documents, or one document.&lt;br /&gt;
*&#039;&#039;&#039;XPath-structure:&#039;&#039;&#039;hierarchical structures without values, such as &amp;lt;br&amp;gt;&amp;lt;code&amp;gt;poem.text.line&amp;lt;/code&amp;gt;&lt;br /&gt;
*&#039;&#039;&#039;XPath-structure-words:&#039;&#039;&#039; hierarchical structures with words, such as &amp;lt;br&amp;gt;&amp;lt;code&amp;gt;poem.text.line: [&amp;quot;Mary&amp;quot;, &amp;quot;had&amp;quot;, &amp;quot;a&amp;quot;, &amp;quot;little&amp;quot;, &amp;quot;lamb&amp;quot;]&amp;lt;/code&amp;gt;&lt;br /&gt;
*&#039;&#039;&#039;XPath-structure-phrases:&#039;&#039;&#039; hierarchical structures with phrases, such as &amp;lt;br&amp;gt;&amp;lt;code&amp;gt;poem.text.line: [&amp;quot;Mary had&amp;quot;, &amp;quot;had a&amp;quot;, &amp;quot;a little&amp;quot;, &amp;quot;little lamb&amp;quot;]&amp;lt;/code&amp;gt;&lt;br /&gt;
*&#039;&#039;&#039;XPath-structure-values:&#039;&#039;&#039; hierarchical structures with values, such as &amp;lt;br&amp;gt;&amp;lt;code&amp;gt;poem.text.line: &amp;quot;Mary had a little lamb&amp;quot;&amp;lt;/code&amp;gt;&lt;br /&gt;
*&#039;&#039;&#039;RDF document links&#039;&#039;&#039; to other documents, such as &amp;lt;br&amp;gt;&amp;lt;code&amp;gt;{&amp;quot;subject&amp;quot;: &amp;quot;http://example.org/documents/thisDoc&amp;quot;, &amp;lt;br&amp;gt;&amp;quot;predicate&amp;quot;: &amp;quot;http://example.org/predicates/relatesSomehowTo&amp;quot;, &amp;lt;br&amp;gt;&amp;quot;object&amp;quot;: &amp;quot;http://example.org/documents/thatDoc&amp;quot;}&amp;lt;/code&amp;gt;&lt;br /&gt;
*&#039;&#039;&#039;RDF abstract links&#039;&#039;&#039; to other abstract concepts, such as &amp;lt;br&amp;gt;&amp;lt;code&amp;gt;{&amp;quot;subject&amp;quot;: &amp;quot;http://example.org/documents/thisDoc&amp;quot;, &amp;lt;br&amp;gt;&amp;quot;predicate&amp;quot;: &amp;quot;http://example.org/predicates/relatesSomehowTo&amp;quot;, &amp;lt;br&amp;gt;&amp;quot;object&amp;quot;: &amp;quot;http://example.org/documents/someConceptWithNoDocumentAtTheURI&amp;quot;}&amp;lt;/code&amp;gt;&lt;br /&gt;
*&#039;&#039;&#039;RDF data links&#039;&#039;&#039; to data, such as &amp;lt;br&amp;gt;&amp;lt;code&amp;gt;{&amp;quot;subject&amp;quot;: &amp;quot;http://example.org/documents/thisDoc&amp;quot;, &amp;lt;br&amp;gt;&amp;quot;predicate&amp;quot;: &amp;quot;http://example.org/predicates/ageInYears&amp;quot;, &amp;lt;br&amp;gt;&amp;quot;object&amp;quot;: 12}&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
MarkLogic can combine any of these indexes in any way to find matching documents.  It can sort the result by relevance or by value. &lt;br /&gt;
&lt;br /&gt;
Search and query expressions are fully composable; i.e. they can be nested inside each other and combined using AND, OR, and NOT expressions.&lt;br /&gt;
&lt;br /&gt;
== Training Resources for MarkLogic Search ==&lt;br /&gt;
* [http://developer.marklogic.com/blog/grokking-the-cts-api &amp;quot;Grokking the cts API&amp;quot;] is a great overview of MarkLogic&#039;s search and query capabilities.&lt;br /&gt;
&lt;br /&gt;
[[Category: MarkLogic]]&lt;/div&gt;</summary>
		<author><name>Bowersmt</name></author>
	</entry>
	<entry>
		<id>https://tech.churchofjesuschrist.org/wiki/index.php?title=What_is_MarkLogic%3F&amp;diff=70554</id>
		<title>What is MarkLogic?</title>
		<link rel="alternate" type="text/html" href="https://tech.churchofjesuschrist.org/wiki/index.php?title=What_is_MarkLogic%3F&amp;diff=70554"/>
		<updated>2014-11-14T08:23:30Z</updated>

		<summary type="html">&lt;p&gt;Bowersmt: Changed category&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;br /&gt;
== What is MarkLogic? ==&lt;br /&gt;
[http://www.marklogic.com/what-is-marklogic/ MarkLogic] is a [http://www.marklogic.com/what-is-marklogic/inside-marklogic/ &#039;&#039;&#039;REST application server&#039;&#039;&#039;, &#039;&#039;&#039;document database&#039;&#039;&#039;, and &#039;&#039;&#039;search engine&#039;&#039;&#039;]. It is REST through and through. It is built specifically for hypertext documents, links, metadata, URIs, MIME types, and HTTP. It is schema-agnostic because it is automatically aware of the independent structure of each of its JSON and XML documents. It is search-centric because it can search for &#039;&#039;any combination&#039;&#039; of words, values, structures, and links within and across documents. It scales horizontally to hundreds of servers within and between data centers while maintaining ACID-compliant transactions. &lt;br /&gt;
&lt;br /&gt;
MarkLogic has the following [http://www.marklogic.com/what-is-marklogic/enterprise-nosql/ enterprise features]:&lt;br /&gt;
* [http://www.marklogic.com/resources/java-developers-guide/ Java APIs]&lt;br /&gt;
* [http://en.wikipedia.org/wiki/Node.js Node.js APIs]&lt;br /&gt;
* [http://developer.marklogic.com/learn/2009-07-search-api-walkthrough Search] and [http://developer.marklogic.com/learn/arch/search-and-indexing Query]&lt;br /&gt;
* [http://www.marklogic.com/blog/can-you-pass-the-acid-test/ ACID Transactions]&lt;br /&gt;
* [http://www.marklogic.com/resources/marklogic-high-availability-and-disaster-recovery/resource_download/datasheets/ High Availability] and [http://docs.marklogic.com/guide/database-replication/dbrep_intro#chapter Disaster Recovery]&lt;br /&gt;
* [http://www.marklogic.com/resources/marklogic-flexible-replication/resource_download/datasheets/ Replication within and across data centers]&lt;br /&gt;
* [http://docs.marklogic.com/guide/admin/security#chapter Government-grade Security]&lt;br /&gt;
* [https://docs.marklogic.com/guide/cluster.pdf Scalability] and [https://docs.marklogic.com/guide/admin/database-rebalancing#chapter Elasticity]&lt;br /&gt;
* [https://docs.marklogic.com/guide/ec2/managing#chapter On-premise or Cloud Deployment (especially AWS)]&lt;br /&gt;
* [http://www.marklogic.com/resources/marklogic-and-hadoop/resource_download/datasheets/ Hadoop for Storage and Compute]&lt;br /&gt;
* [http://www.marklogic.com/resources/marklogic-semantics-mlw14/ Semantics]&lt;br /&gt;
&lt;br /&gt;
== What is REST? ==&lt;br /&gt;
REST is an architectural style that uses a uniform resource identifier (&#039;&#039;&#039;URI&#039;&#039;&#039;) and a web protocol (&#039;&#039;&#039;HTTP/HTTPS&#039;&#039;&#039;) to request and transfer a representation (&#039;&#039;&#039;MIME media type&#039;&#039;&#039;) of the state of a resource (&#039;&#039;&#039;document&#039;&#039;&#039;) at a point in time from a server to a client. &lt;br /&gt;
&lt;br /&gt;
REST was coined and defined by Roy Fielding in his &lt;br /&gt;
[http://www.ics.uci.edu/~fielding/pubs/dissertation/top.htm dissertation, &#039;&#039;Architectural Styles and the Design of Network-based Software Architectures&#039;&#039;].  REST standardizes and documents the patterns used in the world wide web: self-documenting hypertext with data and metadata (HTML), stateless request/response communication protocol (HTTP/HTTPS), resource locators (URL), multiple representations per URL (MIME types), and downloading code on demand to process resources (JavaScript, CSS, etc.).&lt;br /&gt;
&lt;br /&gt;
REST consists of three main concepts: &lt;br /&gt;
* (RE) Representation&lt;br /&gt;
* (S)  State &lt;br /&gt;
* (T)  Transfer &lt;br /&gt;
&lt;br /&gt;
== Why is MarkLogic RESTful? ==&lt;br /&gt;
&lt;br /&gt;
=== &#039;&#039;&#039;Representation and MarkLogic&#039;&#039;&#039; === &lt;br /&gt;
* A representation is a document that represents a resource. It has three requirements: MIME media type, URI, and hypertext.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;MIME type:&#039;&#039;&#039; Each resource can be represented by one or more types of documents. The MIME media type defines the representation a client requests. A client may request the resource to be represented as JSON, XML, HTML, PNG, PDF, etc. &lt;br /&gt;
**&#039;&#039;&#039;MarkLogic&#039;&#039;&#039; stores any type of document and assigns the appropriate [http://developer.marklogic.com/blog/document-formats-part2 MIME type] to it. It can fully index, query, search, and process JSON, XML, and RDF documents. It meets the REST requirement of being able to transform JSON, XML, and RDF documents into any other MIME type. It knows how to execute JavaScript, XQuery, XSLT, and SPARQL documents. It knows how [http://docs.marklogic.com/guide/cpf/default#chapter to transform into XHTML] the content, formatting, and structure of Microsoft Word, PowerPoint, Excel, textual PDF, DocBook, and CSS  documents. (It can also use Microsoft Office to create, edit, and manage content in MarkLogic.) It knows how to [https://docs.marklogic.com/guide/search-dev/binary-document-metadata extract metadata and text from over 138 types of binary documents], such as raster images, vector images, videos, archive files, database files, encoded emails, presentations, spreadsheets, word-processing documents, text formats. &lt;br /&gt;
**Few NoSQL databases use MIME types to identify the media type of each document.  Most NoSQL databases support only one type of data and it is usually proprietary: columnar, BSON, binary, etc. Most cannot transform from one MIME type to another.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;URI:&#039;&#039;&#039; A resource is identified by a globally unique identifier (URI). &#039;&#039;&#039;MarkLogic&#039;&#039;&#039; identifies each document with a [http://developer.marklogic.com/try/rest/page2 unique URI]. A document in MarkLogic is like a row in a table in a schema in a relational database. A URI is liberating. It provides random access to any resource anywhere. It is like being able to retrieve any row in any table in any schema of a relational database without having to know what table and schema the row is stored in.  &lt;br /&gt;
**Navigating URL hierarchy is fundamental to REST. MarkLogic understands the hierarchy within a URI, which is represented by slashes &amp;quot;/&amp;quot;, such as https://www.lds.org/scriptures/ot/gen/1  MarkLogic treats the items between the slashes as folders. The URI of each document automatically places it in a folder in a folder hierarchy. A URI automatically defines the folder hierarchy.  In the example URI above, the document for Genesis chapter 1, is located in the Genesis folder, which is located in the Old Testament folder, which is located in the Scriptures folder on lds.org.  &#039;&#039;&#039;MarkLogic&#039;&#039;&#039; indexes the documents in each folder and its subfolders. This makes it fast and easy to retrieve any or all documents in any folder and/or its subfolders.&lt;br /&gt;
**Few NoSQL databases use the URI as the primary key for their documents or data. They also don&#039;t index the URI hierarchically to filter documents by folder and subfolder.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Hypertext:&#039;&#039;&#039; A document should contain data that represents the resource. The data should be &#039;&#039;&#039;human readable and self-documenting&#039;&#039;&#039;, like JSON, XML, RDF, and HTML. It should be &#039;&#039;&#039;linked data&#039;&#039;&#039; (i.e. the &amp;quot;hyper&amp;quot; in &amp;quot;hypertext&amp;quot;). A document should contain &#039;&#039;&#039; metadata links&#039;&#039;&#039; about the resource, such as RDF. It should contain &#039;&#039;&#039;action links&#039;&#039;&#039; to define what further actions can be done with the resource. It should contain &#039;&#039;&#039;related links&#039;&#039;&#039; to related resources, such as images, audio, video, related documents, etc. Each related link should define what actions can be done with the referenced resource, such as download it, display a link to it, execute a command against it, etc.)&lt;br /&gt;
**&#039;&#039;&#039;Hypertext&#039;&#039;&#039; or &#039;&#039;&#039;hypermedia&#039;&#039;&#039; documents must have all these features. Hyperlinks are what the &amp;quot;hyper&amp;quot; in hypertext and hypermedia refers to.  You can&#039;t have REST without &#039;&#039;metadata links&#039;&#039; to define what the data means, &#039;&#039;action links&#039;&#039; to know how to work with the resource, and &#039;&#039;related links&#039;&#039; to connect resources. It should all be human readable and self-documenting so a developer does not have to read documentation to know how to interact with a REST web service and its documents. &lt;br /&gt;
** &#039;&#039;&#039;MarkLogic&#039;&#039;&#039; meets all the requirements for hypertext representation. It is designed around MIME types, URIs, and Linked data.  It stores documents with their MIME types as [http://www.w3schools.com/json/ JSON], [http://www.w3schools.com/xml/ XML], [http://www.w3schools.com/webservices/ws_rdf_intro.asp RDF], [http://www.w3schools.com/html/ HTML], etc.  These documents are human-readable and self-documenting, which MarkLogic leverages to recognize and index each document&#039;s data, data structure, metadata links, action links, and related links. This makes it easy to &#039;&#039;&#039;search&#039;&#039;&#039;, &#039;&#039;&#039;query&#039;&#039;&#039;, &#039;&#039;&#039;transform&#039;&#039;&#039;, and &#039;&#039;&#039;deliver&#039;&#039;&#039; hypertext documents.  MarkLogic can also store any type of binary document and deliver it as a related resource, such as an image, video, or audio. MarkLogic is designed to process simple links and RDF links using [http://en.wikipedia.org/wiki/SPARQL SPARQL] and [https://docs.marklogic.com/xinc XInclude]. MarkLogic can represent links in many formats:  [https://docs.marklogic.com/xp XPointer], [https://docs.marklogic.com/guide/semantics/loading#id_97709 RDF/XML], [https://docs.marklogic.com/guide/semantics/loading#id_79194 RDF/JSON], [https://docs.marklogic.com/guide/semantics/loading#id_73211 Turtle], [https://docs.marklogic.com/guide/semantics/loading#id_70596 N-Triples], [https://docs.marklogic.com/guide/semantics/loading#id_61596 N-Quads], and [https://docs.marklogic.com/guide/semantics/loading#id_74485 TriG].&lt;br /&gt;
**No other NoSQL database natively indexes and fully processes all the document types required for REST hypertext: JSON, XML, RDF, HTML, CSS, and JavaScript.&lt;br /&gt;
&lt;br /&gt;
=== &#039;&#039;&#039;State and MarkLogic&#039;&#039;&#039; === &lt;br /&gt;
* State in REST exists on the client and in server documents. It does not exist in the communications protocol or in the server as cached session data. &lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Server:&#039;&#039;&#039; All information needed to process a request must be presented in the request and processed against documents in the database. State must only be in the request and in database documents: state cannot be anywhere else, such as in a session cache. The documents in the server define the state of the server. A REST server should explicitly create a state machine that defines the acceptable actions that can transacted against documents in specific contexts.&lt;br /&gt;
**A REST transaction occurs at a &#039;&#039;&#039;point in time&#039;&#039;&#039;. The state of the data in the request is unchanging, but the state of the documents and state machines in the database are often changing. Since request state and database state are both required to process the request and since shifting state creates unpredictable results, a REST transaction should run at a point in time with unchanging state. Only an ACID-compliant database can ensure consistent state because it isolates each transaction from every other transaction. The only time REST does not need an ACID-compliant database is when database documents do not change, database state machines do not change, or when clients can live with the resultant level of unreliable and unpredictable results.&lt;br /&gt;
**&#039;&#039;&#039;MarkLogic&#039;&#039;&#039; meets all the requirements for REST state.  Its web services are stateless: there is no session cache. It is ACID compliant. It ensures each transaction occurs at a point in time and is isolated from all other transactions. This ensures consistent processing during a transaction -- even across billions of documents. MarkLogic is an [http://en.wikipedia.org/wiki/Multiversion_concurrency_control MVCC] database which provides transaction isolation without slowing the performance of reads -- even when documents being read are being modified simultaneously by other transactions. (Also, like any other ACID database, when multiple updates and deletes compete for the same documents, they will impact each other&#039;s performance because change has to be serialized.)  &lt;br /&gt;
** Most other NoSQL databases are not ACID compliant. They are only suitable for REST services when their documents or data do not change or when the rate of change is slow enough or dispersed enough that it creates an acceptable level of unreliability and unpredictability.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Client:&#039;&#039;&#039; A REST client, such as a web browser or spider, locally maintains transactional state, such as what to do in response to documents and result codes that are returned from server transactions. An application exists only in the client -- not in the server (although, a server may deliver application code to a client, such as when a web server downloads HTML, CSS, and JavaScript to a browser). Client application code decides when to execute web service calls and it ties the results together to accomplish its purpose. This allows multiple authorized applications to reuse web services for a variety of purposes.  &lt;br /&gt;
**The server helps the client know what web service calls are available by providing action links with each response.  Action links are contextual and the context is based on the application account, user account, database documents, links within and between documents, the server state machine, etc. Through action links, the server can inform a client application what web service calls are permissible in any given context.&lt;br /&gt;
**&#039;&#039;&#039;MarkLogic&#039;&#039;&#039; meets the needs of client applications through its built-in ability to process and send action links to clients based on context. MarkLogic supports RDF triples and SPARQL, which enables context to be defined across applications, users, document state, links between documents, server state machine, etc. MarkLogic processes triples very quickly, which enables context to scale to billions of documents, millions of users, etc.&lt;br /&gt;
**&#039;&#039;&#039;MarkLogic&#039;&#039;&#039; also uses application and user permissions to filter which documents are returned to clients.  MarkLogic does this automatically and transparently by adding security filtering constraints into every search and query. This ensures no account can access unauthorized documents. This is fast because all security permissions are built-into MarkLogic&#039;s indexes -- which allows document-level security to scale across billions of documents.&lt;br /&gt;
** Most other NoSQL databases do not provide government-grade, document-level security and they also do not support RDF triples and SPARQL.&lt;br /&gt;
&lt;br /&gt;
Because MarkLogic can provide both the web service and database in one server, it is easy to use the state of the documents and the &lt;br /&gt;
&lt;br /&gt;
=== &#039;&#039;&#039;Transfer and MarkLogic&#039;&#039;&#039; === &lt;br /&gt;
* &#039;&#039;&#039;Transfer&#039;&#039;&#039; in REST is a communication protocol that enables a client to send a hypertext request to a server and receive back a hypertext response. The transfer must be stateless and be a request/response protocol. It must have human readable, self-descriptive headers.  The header must contain metadata about the request, such as the requested resource URI, MIME type of the resource, action to perform on the resource (such as get, put, post, patch, and delete). [http://www.w3schools.com/tags/ref_httpmethods.asp &#039;&#039;&#039;HTTP&#039;&#039;&#039;] (Hypertext transfer protocol) and &#039;&#039;&#039;HTTPS&#039;&#039;&#039; (secure HTTP) are designed specifically for REST (that is why they have &amp;quot;hypertext&amp;quot; in their name).&lt;br /&gt;
&lt;br /&gt;
* All &#039;&#039;&#039;MarkLogic&#039;&#039;&#039; communication is through through HTTP and HTTPS REST services (except for its SQL JDBC feature). This includes all internal cluster communication.  MarkLogic provides out-of-the-box REST interfaces for manipulating resources (insert, update, delete, query, search, transform, etc.) and administering MarkLogic (REST app servers, databases, indexes, clusters, etc).  MarkLogic makes it very easy to create custom REST services because everything in MarkLogic is built around REST and because they provide simple and powerful application server APIs.&lt;br /&gt;
&lt;br /&gt;
== MarkLogic Query and Search ==&lt;br /&gt;
MarkLogic is unlike relational databases (and a few NoSQL databases) where they use full table scans to retrieve every row in the table unless a query accesses less than 20% of the rows and then they use an index.  MarkLogic does not do full table scans.  It needs all queries to be resolved out of the indexes.  For that reason, it indexes most things and allows you to index more.&lt;br /&gt;
&lt;br /&gt;
MarkLogic can query and search -- and use both in combination.  MarkLogic uses indexes to execute searches and queries. The same indexes are used for both.  The difference between search and query is how documents are sorted.  Searches sort by relevance and queries sort by values. MarkLogic uses indexes to extract words, values, structures, and links out of documents. &lt;br /&gt;
&lt;br /&gt;
This enables you to search and query for documents as if they contained only&lt;br /&gt;
*&#039;&#039;&#039;Words:&#039;&#039;&#039; a flat set of words without structure, such as &amp;lt;br&amp;gt;&amp;lt;code&amp;gt;[&amp;quot;Mary&amp;quot; &amp;quot;had&amp;quot;, &amp;quot;a&amp;quot;, &amp;quot;little&amp;quot;, &amp;quot;lamb&amp;quot;]&amp;lt;/code&amp;gt;&lt;br /&gt;
*&#039;&#039;&#039;Phrases:&#039;&#039;&#039; a flat set of phrases without structure, such as &amp;lt;br&amp;gt;&amp;lt;code&amp;gt;[&amp;quot;Mary had&amp;quot;, &amp;quot;had a&amp;quot;, &amp;quot;a little&amp;quot;, &amp;quot;little lamb&amp;quot;]&amp;lt;/code&amp;gt;&lt;br /&gt;
*&#039;&#039;&#039;Elements:&#039;&#039;&#039; a flat set of elements without values, such as &amp;lt;br&amp;gt;&amp;lt;code&amp;gt;[&amp;quot;poem&amp;quot;, &amp;quot;text&amp;quot;, &amp;quot;line&amp;quot;]&amp;lt;/code&amp;gt;&lt;br /&gt;
*&#039;&#039;&#039;Element-values:&#039;&#039;&#039; a flat set of elements with string values, such as &amp;lt;br&amp;gt;&amp;lt;code&amp;gt;&amp;quot;line&amp;quot;: &amp;quot;Mary had a little lamb&amp;quot;&amp;lt;/code&amp;gt;&lt;br /&gt;
*&#039;&#039;&#039;Element-words:&#039;&#039;&#039; a flat set of elements with words, such as &amp;lt;br&amp;gt;&amp;lt;code&amp;gt;&amp;quot;line&amp;quot;: [&amp;quot;Mary&amp;quot; &amp;quot;had&amp;quot;, &amp;quot;a&amp;quot;, &amp;quot;little&amp;quot;, &amp;quot;lamb&amp;quot;]&amp;lt;/code&amp;gt;&lt;br /&gt;
*&#039;&#039;&#039;Element-phrases:&#039;&#039;&#039; a flat set of elements with phrases, such as &amp;lt;br&amp;gt;&amp;lt;code&amp;gt;&amp;quot;line&amp;quot;: [&amp;quot;Mary had&amp;quot;, &amp;quot;had a&amp;quot;, &amp;quot;a little&amp;quot;, &amp;quot;little lamb&amp;quot;]&amp;lt;/code&amp;gt;&lt;br /&gt;
*&#039;&#039;&#039;Element-value lexicon:&#039;&#039;&#039; a flat set of elements with typed values, such as &amp;lt;br&amp;gt;&amp;lt;code&amp;gt;&amp;quot;lineSequence&amp;quot;: 3&amp;lt;/code&amp;gt;&amp;lt;br&amp;gt; or a list, count, or co-occurrence of element values scoped to a database, set of documents, or one document.&lt;br /&gt;
*&#039;&#039;&#039;XPath-structure-value lexicon:&#039;&#039;&#039; a flat set of hierarchical elements with typed values, such as &amp;lt;br&amp;gt;&amp;lt;code&amp;gt;poem.text.line.lineSequence: 3&amp;lt;/code&amp;gt;&amp;lt;br&amp;gt; or a list, count, or co-occurrence of hierarchical element values scoped to a database, set of documents, or one document.&lt;br /&gt;
*&#039;&#039;&#039;XPath-structure:&#039;&#039;&#039;hierarchical structures without values, such as &amp;lt;br&amp;gt;&amp;lt;code&amp;gt;poem.text.line&amp;lt;/code&amp;gt;&lt;br /&gt;
*&#039;&#039;&#039;XPath-structure-words:&#039;&#039;&#039; hierarchical structures with words, such as &amp;lt;br&amp;gt;&amp;lt;code&amp;gt;poem.text.line: [&amp;quot;Mary&amp;quot;, &amp;quot;had&amp;quot;, &amp;quot;a&amp;quot;, &amp;quot;little&amp;quot;, &amp;quot;lamb&amp;quot;]&amp;lt;/code&amp;gt;&lt;br /&gt;
*&#039;&#039;&#039;XPath-structure-phrases:&#039;&#039;&#039; hierarchical structures with phrases, such as &amp;lt;br&amp;gt;&amp;lt;code&amp;gt;poem.text.line: [&amp;quot;Mary had&amp;quot;, &amp;quot;had a&amp;quot;, &amp;quot;a little&amp;quot;, &amp;quot;little lamb&amp;quot;]&amp;lt;/code&amp;gt;&lt;br /&gt;
*&#039;&#039;&#039;XPath-structure-values:&#039;&#039;&#039; hierarchical structures with values, such as &amp;lt;br&amp;gt;&amp;lt;code&amp;gt;poem.text.line: &amp;quot;Mary had a little lamb&amp;quot;&amp;lt;/code&amp;gt;&lt;br /&gt;
*&#039;&#039;&#039;RDF document links&#039;&#039;&#039; to other documents, such as &amp;lt;br&amp;gt;&amp;lt;code&amp;gt;{&amp;quot;subject&amp;quot;: &amp;quot;http://example.org/documents/thisDoc&amp;quot;, &amp;quot;predicate&amp;quot;: &amp;quot;http://example.org/predicates/relatesSomehowTo&amp;quot;, &amp;quot;object&amp;quot;: &amp;quot;http://example.org/documents/thatDoc&amp;quot;}&amp;lt;/code&amp;gt;&lt;br /&gt;
*&#039;&#039;&#039;RDF abstract links&#039;&#039;&#039; to other abstract concepts, such as &amp;lt;br&amp;gt;&amp;lt;code&amp;gt;{&amp;quot;subject&amp;quot;: &amp;quot;http://example.org/documents/thisDoc&amp;quot;, &amp;quot;predicate&amp;quot;: &amp;quot;http://example.org/predicates/relatesSomehowTo&amp;quot;, &amp;quot;object&amp;quot;: &amp;quot;http://example.org/documents/someConceptWithNoDocumentAtTheURI&amp;quot;}&amp;lt;/code&amp;gt;&lt;br /&gt;
*&#039;&#039;&#039;RDF data links&#039;&#039;&#039; to data, such as &amp;lt;br&amp;gt;&amp;lt;code&amp;gt;{&amp;quot;subject&amp;quot;: &amp;quot;http://example.org/documents/thisDoc&amp;quot;, &amp;quot;predicate&amp;quot;: &amp;quot;http://example.org/predicates/ageInYears&amp;quot;, &amp;quot;object&amp;quot;: 12}&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
MarkLogic can combine any of these indexes in any way to find matching documents.  It can sort the result by relevance or by value. &lt;br /&gt;
&lt;br /&gt;
The [[MarkLogic Query and Search]] page provides more detail about how MarkLogic&#039;s unique indexes work and how they work together.&lt;br /&gt;
&lt;br /&gt;
[[Category: MarkLogic]]&lt;/div&gt;</summary>
		<author><name>Bowersmt</name></author>
	</entry>
	<entry>
		<id>https://tech.churchofjesuschrist.org/wiki/index.php?title=MarkLogic&amp;diff=70553</id>
		<title>MarkLogic</title>
		<link rel="alternate" type="text/html" href="https://tech.churchofjesuschrist.org/wiki/index.php?title=MarkLogic&amp;diff=70553"/>
		<updated>2014-11-14T08:22:52Z</updated>

		<summary type="html">&lt;p&gt;Bowersmt: Changed category&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== MarkLogic ==&lt;br /&gt;
This is the landing page for MarkLogic.  MarkLogic is an all-in-one application server, document database, and search engine.  It is entirely based on REST. For an extensive explanation of what MarkLogic is and what it can do, see [[What is MarkLogic?]]&lt;br /&gt;
&lt;br /&gt;
== Links to other MarkLogic Documents ==&lt;br /&gt;
* [[What is MarkLogic?]]&lt;br /&gt;
* [[Installing MarkLogic]]&lt;br /&gt;
* [[MarkLogic Training Resources]]&lt;br /&gt;
&lt;br /&gt;
[[Category: MarkLogic]]&lt;/div&gt;</summary>
		<author><name>Bowersmt</name></author>
	</entry>
	<entry>
		<id>https://tech.churchofjesuschrist.org/wiki/index.php?title=What_is_MarkLogic%3F&amp;diff=70550</id>
		<title>What is MarkLogic?</title>
		<link rel="alternate" type="text/html" href="https://tech.churchofjesuschrist.org/wiki/index.php?title=What_is_MarkLogic%3F&amp;diff=70550"/>
		<updated>2014-11-14T08:17:04Z</updated>

		<summary type="html">&lt;p&gt;Bowersmt: Changed category&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;br /&gt;
== What is MarkLogic? ==&lt;br /&gt;
[http://www.marklogic.com/what-is-marklogic/ MarkLogic] is a [http://www.marklogic.com/what-is-marklogic/inside-marklogic/ &#039;&#039;&#039;REST application server&#039;&#039;&#039;, &#039;&#039;&#039;document database&#039;&#039;&#039;, and &#039;&#039;&#039;search engine&#039;&#039;&#039;]. It is REST through and through. It is built specifically for hypertext documents, links, metadata, URIs, MIME types, and HTTP. It is schema-agnostic because it is automatically aware of the independent structure of each of its JSON and XML documents. It is search-centric because it can search for &#039;&#039;any combination&#039;&#039; of words, values, structures, and links within and across documents. It scales horizontally to hundreds of servers within and between data centers while maintaining ACID-compliant transactions. &lt;br /&gt;
&lt;br /&gt;
MarkLogic has the following [http://www.marklogic.com/what-is-marklogic/enterprise-nosql/ enterprise features]:&lt;br /&gt;
* [http://www.marklogic.com/resources/java-developers-guide/ Java APIs]&lt;br /&gt;
* [http://en.wikipedia.org/wiki/Node.js Node.js APIs]&lt;br /&gt;
* [http://developer.marklogic.com/learn/2009-07-search-api-walkthrough Search] and [http://developer.marklogic.com/learn/arch/search-and-indexing Query]&lt;br /&gt;
* [http://www.marklogic.com/blog/can-you-pass-the-acid-test/ ACID Transactions]&lt;br /&gt;
* [http://www.marklogic.com/resources/marklogic-high-availability-and-disaster-recovery/resource_download/datasheets/ High Availability] and [http://docs.marklogic.com/guide/database-replication/dbrep_intro#chapter Disaster Recovery]&lt;br /&gt;
* [http://www.marklogic.com/resources/marklogic-flexible-replication/resource_download/datasheets/ Replication within and across data centers]&lt;br /&gt;
* [http://docs.marklogic.com/guide/admin/security#chapter Government-grade Security]&lt;br /&gt;
* [https://docs.marklogic.com/guide/cluster.pdf Scalability] and [https://docs.marklogic.com/guide/admin/database-rebalancing#chapter Elasticity]&lt;br /&gt;
* [https://docs.marklogic.com/guide/ec2/managing#chapter On-premise or Cloud Deployment (especially AWS)]&lt;br /&gt;
* [http://www.marklogic.com/resources/marklogic-and-hadoop/resource_download/datasheets/ Hadoop for Storage and Compute]&lt;br /&gt;
* [http://www.marklogic.com/resources/marklogic-semantics-mlw14/ Semantics]&lt;br /&gt;
&lt;br /&gt;
== What is REST? ==&lt;br /&gt;
REST is an architectural style that uses a uniform resource identifier (&#039;&#039;&#039;URI&#039;&#039;&#039;) and a web protocol (&#039;&#039;&#039;HTTP/HTTPS&#039;&#039;&#039;) to request and transfer a representation (&#039;&#039;&#039;MIME media type&#039;&#039;&#039;) of the state of a resource (&#039;&#039;&#039;document&#039;&#039;&#039;) at a point in time from a server to a client. &lt;br /&gt;
&lt;br /&gt;
REST was coined and defined by Roy Fielding in his &lt;br /&gt;
[http://www.ics.uci.edu/~fielding/pubs/dissertation/top.htm dissertation, &#039;&#039;Architectural Styles and the Design of Network-based Software Architectures&#039;&#039;].  REST standardizes and documents the patterns used in the world wide web: self-documenting hypertext with data and metadata (HTML), stateless request/response communication protocol (HTTP/HTTPS), resource locators (URL), multiple representations per URL (MIME types), and downloading code on demand to process resources (JavaScript, CSS, etc.).&lt;br /&gt;
&lt;br /&gt;
REST consists of three main concepts: &lt;br /&gt;
* (RE) Representation&lt;br /&gt;
* (S)  State &lt;br /&gt;
* (T)  Transfer &lt;br /&gt;
&lt;br /&gt;
== Why is MarkLogic RESTful? ==&lt;br /&gt;
&lt;br /&gt;
=== &#039;&#039;&#039;Representation and MarkLogic&#039;&#039;&#039; === &lt;br /&gt;
* A representation is a document that represents a resource. It has three requirements: MIME media type, URI, and hypertext.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;MIME type:&#039;&#039;&#039; Each resource can be represented by one or more types of documents. The MIME media type defines the representation a client requests. A client may request the resource to be represented as JSON, XML, HTML, PNG, PDF, etc. &lt;br /&gt;
**&#039;&#039;&#039;MarkLogic&#039;&#039;&#039; stores any type of document and assigns the appropriate [http://developer.marklogic.com/blog/document-formats-part2 MIME type] to it. It can fully index, query, search, and process JSON, XML, and RDF documents. It meets the REST requirement of being able to transform JSON, XML, and RDF documents into any other MIME type. It knows how to execute JavaScript, XQuery, XSLT, and SPARQL documents. It knows how [http://docs.marklogic.com/guide/cpf/default#chapter to transform into XHTML] the content, formatting, and structure of Microsoft Word, PowerPoint, Excel, textual PDF, DocBook, and CSS  documents. (It can also use Microsoft Office to create, edit, and manage content in MarkLogic.) It knows how to [https://docs.marklogic.com/guide/search-dev/binary-document-metadata extract metadata and text from over 138 types of binary documents], such as raster images, vector images, videos, archive files, database files, encoded emails, presentations, spreadsheets, word-processing documents, text formats. &lt;br /&gt;
**Few NoSQL databases use MIME types to identify the media type of each document.  Most NoSQL databases support only one type of data and it is usually proprietary: columnar, BSON, binary, etc. Most cannot transform from one MIME type to another.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;URI:&#039;&#039;&#039; A resource is identified by a globally unique identifier (URI). &#039;&#039;&#039;MarkLogic&#039;&#039;&#039; identifies each document with a [http://developer.marklogic.com/try/rest/page2 unique URI]. A document in MarkLogic is like a row in a table in a schema in a relational database. A URI is liberating. It provides random access to any resource anywhere. It is like being able to retrieve any row in any table in any schema of a relational database without having to know what table and schema the row is stored in.  &lt;br /&gt;
**Navigating URL hierarchy is fundamental to REST. MarkLogic understands the hierarchy within a URI, which is represented by slashes &amp;quot;/&amp;quot;, such as https://www.lds.org/scriptures/ot/gen/1  MarkLogic treats the items between the slashes as folders. The URI of each document automatically places it in a folder in a folder hierarchy. A URI automatically defines the folder hierarchy.  In the example URI above, the document for Genesis chapter 1, is located in the Genesis folder, which is located in the Old Testament folder, which is located in the Scriptures folder on lds.org.  &#039;&#039;&#039;MarkLogic&#039;&#039;&#039; indexes the documents in each folder and its subfolders. This makes it fast and easy to retrieve any or all documents in any folder and/or its subfolders.&lt;br /&gt;
**Few NoSQL databases use the URI as the primary key for their documents or data. They also don&#039;t index the URI hierarchically to filter documents by folder and subfolder.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Hypertext:&#039;&#039;&#039; A document should contain data that represents the resource. The data should be &#039;&#039;&#039;human readable and self-documenting&#039;&#039;&#039;, like JSON, XML, RDF, and HTML. It should be &#039;&#039;&#039;linked data&#039;&#039;&#039; (i.e. the &amp;quot;hyper&amp;quot; in &amp;quot;hypertext&amp;quot;). A document should contain &#039;&#039;&#039; metadata links&#039;&#039;&#039; about the resource, such as RDF. It should contain &#039;&#039;&#039;action links&#039;&#039;&#039; to define what further actions can be done with the resource. It should contain &#039;&#039;&#039;related links&#039;&#039;&#039; to related resources, such as images, audio, video, related documents, etc. Each related link should define what actions can be done with the referenced resource, such as download it, display a link to it, execute a command against it, etc.)&lt;br /&gt;
**&#039;&#039;&#039;Hypertext&#039;&#039;&#039; or &#039;&#039;&#039;hypermedia&#039;&#039;&#039; documents must have all these features. Hyperlinks are what the &amp;quot;hyper&amp;quot; in hypertext and hypermedia refers to.  You can&#039;t have REST without &#039;&#039;metadata links&#039;&#039; to define what the data means, &#039;&#039;action links&#039;&#039; to know how to work with the resource, and &#039;&#039;related links&#039;&#039; to connect resources. It should all be human readable and self-documenting so a developer does not have to read documentation to know how to interact with a REST web service and its documents. &lt;br /&gt;
** &#039;&#039;&#039;MarkLogic&#039;&#039;&#039; meets all the requirements for hypertext representation. It is designed around MIME types, URIs, and Linked data.  It stores documents with their MIME types as [http://www.w3schools.com/json/ JSON], [http://www.w3schools.com/xml/ XML], [http://www.w3schools.com/webservices/ws_rdf_intro.asp RDF], [http://www.w3schools.com/html/ HTML], etc.  These documents are human-readable and self-documenting, which MarkLogic leverages to recognize and index each document&#039;s data, data structure, metadata links, action links, and related links. This makes it easy to &#039;&#039;&#039;search&#039;&#039;&#039;, &#039;&#039;&#039;query&#039;&#039;&#039;, &#039;&#039;&#039;transform&#039;&#039;&#039;, and &#039;&#039;&#039;deliver&#039;&#039;&#039; hypertext documents.  MarkLogic can also store any type of binary document and deliver it as a related resource, such as an image, video, or audio. MarkLogic is designed to process simple links and RDF links using [http://en.wikipedia.org/wiki/SPARQL SPARQL] and [https://docs.marklogic.com/xinc XInclude]. MarkLogic can represent links in many formats:  [https://docs.marklogic.com/xp XPointer], [https://docs.marklogic.com/guide/semantics/loading#id_97709 RDF/XML], [https://docs.marklogic.com/guide/semantics/loading#id_79194 RDF/JSON], [https://docs.marklogic.com/guide/semantics/loading#id_73211 Turtle], [https://docs.marklogic.com/guide/semantics/loading#id_70596 N-Triples], [https://docs.marklogic.com/guide/semantics/loading#id_61596 N-Quads], and [https://docs.marklogic.com/guide/semantics/loading#id_74485 TriG].&lt;br /&gt;
**No other NoSQL database natively indexes and fully processes all the document types required for REST hypertext: JSON, XML, RDF, HTML, CSS, and JavaScript.&lt;br /&gt;
&lt;br /&gt;
=== &#039;&#039;&#039;State and MarkLogic&#039;&#039;&#039; === &lt;br /&gt;
* State in REST exists on the client and in server documents. It does not exist in the communications protocol or in the server as cached session data. &lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Server:&#039;&#039;&#039; All information needed to process a request must be presented in the request and processed against documents in the database. State must only be in the request and in database documents: state cannot be anywhere else, such as in a session cache. The documents in the server define the state of the server. A REST server should explicitly create a state machine that defines the acceptable actions that can transacted against documents in specific contexts.&lt;br /&gt;
**A REST transaction occurs at a &#039;&#039;&#039;point in time&#039;&#039;&#039;. The state of the data in the request is unchanging, but the state of the documents and state machines in the database are often changing. Since request state and database state are both required to process the request and since shifting state creates unpredictable results, a REST transaction should run at a point in time with unchanging state. Only an ACID-compliant database can ensure consistent state because it isolates each transaction from every other transaction. The only time REST does not need an ACID-compliant database is when database documents do not change, database state machines do not change, or when clients can live with the resultant level of unreliable and unpredictable results.&lt;br /&gt;
**&#039;&#039;&#039;MarkLogic&#039;&#039;&#039; meets all the requirements for REST state.  Its web services are stateless: there is no session cache. It is ACID compliant. It ensures each transaction occurs at a point in time and is isolated from all other transactions. This ensures consistent processing during a transaction -- even across billions of documents. MarkLogic is an [http://en.wikipedia.org/wiki/Multiversion_concurrency_control MVCC] database which provides transaction isolation without slowing the performance of reads -- even when documents being read are being modified simultaneously by other transactions. (Also, like any other ACID database, when multiple updates and deletes compete for the same documents, they will impact each other&#039;s performance because change has to be serialized.)  &lt;br /&gt;
** Most other NoSQL databases are not ACID compliant. They are only suitable for REST services when their documents or data do not change or when the rate of change is slow enough or dispersed enough that it creates an acceptable level of unreliability and unpredictability.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Client:&#039;&#039;&#039; A REST client, such as a web browser or spider, locally maintains transactional state, such as what to do in response to documents and result codes that are returned from server transactions. An application exists only in the client -- not in the server (although, a server may deliver application code to a client, such as when a web server downloads HTML, CSS, and JavaScript to a browser). Client application code decides when to execute web service calls and it ties the results together to accomplish its purpose. This allows multiple authorized applications to reuse web services for a variety of purposes.  &lt;br /&gt;
**The server helps the client know what web service calls are available by providing action links with each response.  Action links are contextual and the context is based on the application account, user account, database documents, links within and between documents, the server state machine, etc. Through action links, the server can inform a client application what web service calls are permissible in any given context.&lt;br /&gt;
**&#039;&#039;&#039;MarkLogic&#039;&#039;&#039; meets the needs of client applications through its built-in ability to process and send action links to clients based on context. MarkLogic supports RDF triples and SPARQL, which enables context to be defined across applications, users, document state, links between documents, server state machine, etc. MarkLogic processes triples very quickly, which enables context to scale to billions of documents, millions of users, etc.&lt;br /&gt;
**&#039;&#039;&#039;MarkLogic&#039;&#039;&#039; also uses application and user permissions to filter which documents are returned to clients.  MarkLogic does this automatically and transparently by adding security filtering constraints into every search and query. This ensures no account can access unauthorized documents. This is fast because all security permissions are built-into MarkLogic&#039;s indexes -- which allows document-level security to scale across billions of documents.&lt;br /&gt;
** Most other NoSQL databases do not provide government-grade, document-level security and they also do not support RDF triples and SPARQL.&lt;br /&gt;
&lt;br /&gt;
Because MarkLogic can provide both the web service and database in one server, it is easy to use the state of the documents and the &lt;br /&gt;
&lt;br /&gt;
=== &#039;&#039;&#039;Transfer and MarkLogic&#039;&#039;&#039; === &lt;br /&gt;
* &#039;&#039;&#039;Transfer&#039;&#039;&#039; in REST is a communication protocol that enables a client to send a hypertext request to a server and receive back a hypertext response. The transfer must be stateless and be a request/response protocol. It must have human readable, self-descriptive headers.  The header must contain metadata about the request, such as the requested resource URI, MIME type of the resource, action to perform on the resource (such as get, put, post, patch, and delete). [http://www.w3schools.com/tags/ref_httpmethods.asp &#039;&#039;&#039;HTTP&#039;&#039;&#039;] (Hypertext transfer protocol) and &#039;&#039;&#039;HTTPS&#039;&#039;&#039; (secure HTTP) are designed specifically for REST (that is why they have &amp;quot;hypertext&amp;quot; in their name).&lt;br /&gt;
&lt;br /&gt;
* All &#039;&#039;&#039;MarkLogic&#039;&#039;&#039; communication is through through HTTP and HTTPS REST services (except for its SQL JDBC feature). This includes all internal cluster communication.  MarkLogic provides out-of-the-box REST interfaces for manipulating resources (insert, update, delete, query, search, transform, etc.) and administering MarkLogic (REST app servers, databases, indexes, clusters, etc).  MarkLogic makes it very easy to create custom REST services because everything in MarkLogic is built around REST and because they provide simple and powerful application server APIs.&lt;br /&gt;
&lt;br /&gt;
== MarkLogic Query and Search ==&lt;br /&gt;
MarkLogic is unlike relational databases (and a few NoSQL databases) where they use full table scans to retrieve every row in the table unless a query accesses less than 20% of the rows and then they use an index.  MarkLogic does not do full table scans.  It needs all queries to be resolved out of the indexes.  For that reason, it indexes most things and allows you to index more.&lt;br /&gt;
&lt;br /&gt;
MarkLogic can query and search -- and use both in combination.  MarkLogic uses indexes to execute searches and queries. The same indexes are used for both.  The difference between search and query is how documents are sorted.  Searches sort by relevance and queries sort by values. MarkLogic uses indexes to extract words, values, structures, and links out of documents. &lt;br /&gt;
&lt;br /&gt;
This enables you to search and query for documents as if they contained only&lt;br /&gt;
*&#039;&#039;&#039;Words:&#039;&#039;&#039; a flat set of words without structure, such as &amp;lt;br&amp;gt;&amp;lt;code&amp;gt;[&amp;quot;Mary&amp;quot; &amp;quot;had&amp;quot;, &amp;quot;a&amp;quot;, &amp;quot;little&amp;quot;, &amp;quot;lamb&amp;quot;]&amp;lt;/code&amp;gt;&lt;br /&gt;
*&#039;&#039;&#039;Phrases:&#039;&#039;&#039; a flat set of phrases without structure, such as &amp;lt;br&amp;gt;&amp;lt;code&amp;gt;[&amp;quot;Mary had&amp;quot;, &amp;quot;had a&amp;quot;, &amp;quot;a little&amp;quot;, &amp;quot;little lamb&amp;quot;]&amp;lt;/code&amp;gt;&lt;br /&gt;
*&#039;&#039;&#039;Elements:&#039;&#039;&#039; a flat set of elements without values, such as &amp;lt;br&amp;gt;&amp;lt;code&amp;gt;[&amp;quot;poem&amp;quot;, &amp;quot;text&amp;quot;, &amp;quot;line&amp;quot;]&amp;lt;/code&amp;gt;&lt;br /&gt;
*&#039;&#039;&#039;Element-values:&#039;&#039;&#039; a flat set of elements with string values, such as &amp;lt;br&amp;gt;&amp;lt;code&amp;gt;&amp;quot;line&amp;quot;: &amp;quot;Mary had a little lamb&amp;quot;&amp;lt;/code&amp;gt;&lt;br /&gt;
*&#039;&#039;&#039;Element-words:&#039;&#039;&#039; a flat set of elements with words, such as &amp;lt;br&amp;gt;&amp;lt;code&amp;gt;&amp;quot;line&amp;quot;: [&amp;quot;Mary&amp;quot; &amp;quot;had&amp;quot;, &amp;quot;a&amp;quot;, &amp;quot;little&amp;quot;, &amp;quot;lamb&amp;quot;]&amp;lt;/code&amp;gt;&lt;br /&gt;
*&#039;&#039;&#039;Element-phrases:&#039;&#039;&#039; a flat set of elements with phrases, such as &amp;lt;br&amp;gt;&amp;lt;code&amp;gt;&amp;quot;line&amp;quot;: [&amp;quot;Mary had&amp;quot;, &amp;quot;had a&amp;quot;, &amp;quot;a little&amp;quot;, &amp;quot;little lamb&amp;quot;]&amp;lt;/code&amp;gt;&lt;br /&gt;
*&#039;&#039;&#039;Element-value lexicon:&#039;&#039;&#039; a flat set of elements with typed values, such as &amp;lt;br&amp;gt;&amp;lt;code&amp;gt;&amp;quot;lineSequence&amp;quot;: 3&amp;lt;/code&amp;gt;&amp;lt;br&amp;gt; or a list, count, or co-occurrence of element values scoped to a database, set of documents, or one document.&lt;br /&gt;
*&#039;&#039;&#039;XPath-structure-value lexicon:&#039;&#039;&#039; a flat set of hierarchical elements with typed values, such as &amp;lt;br&amp;gt;&amp;lt;code&amp;gt;poem.text.line.lineSequence: 3&amp;lt;/code&amp;gt;&amp;lt;br&amp;gt; or a list, count, or co-occurrence of hierarchical element values scoped to a database, set of documents, or one document.&lt;br /&gt;
*&#039;&#039;&#039;XPath-structure:&#039;&#039;&#039;hierarchical structures without values, such as &amp;lt;br&amp;gt;&amp;lt;code&amp;gt;poem.text.line&amp;lt;/code&amp;gt;&lt;br /&gt;
*&#039;&#039;&#039;XPath-structure-words:&#039;&#039;&#039; hierarchical structures with words, such as &amp;lt;br&amp;gt;&amp;lt;code&amp;gt;poem.text.line: [&amp;quot;Mary&amp;quot;, &amp;quot;had&amp;quot;, &amp;quot;a&amp;quot;, &amp;quot;little&amp;quot;, &amp;quot;lamb&amp;quot;]&amp;lt;/code&amp;gt;&lt;br /&gt;
*&#039;&#039;&#039;XPath-structure-phrases:&#039;&#039;&#039; hierarchical structures with phrases, such as &amp;lt;br&amp;gt;&amp;lt;code&amp;gt;poem.text.line: [&amp;quot;Mary had&amp;quot;, &amp;quot;had a&amp;quot;, &amp;quot;a little&amp;quot;, &amp;quot;little lamb&amp;quot;]&amp;lt;/code&amp;gt;&lt;br /&gt;
*&#039;&#039;&#039;XPath-structure-values:&#039;&#039;&#039; hierarchical structures with values, such as &amp;lt;br&amp;gt;&amp;lt;code&amp;gt;poem.text.line: &amp;quot;Mary had a little lamb&amp;quot;&amp;lt;/code&amp;gt;&lt;br /&gt;
*&#039;&#039;&#039;RDF document links&#039;&#039;&#039; to other documents, such as &amp;lt;br&amp;gt;&amp;lt;code&amp;gt;{&amp;quot;subject&amp;quot;: &amp;quot;http://example.org/documents/thisDoc&amp;quot;, &amp;quot;predicate&amp;quot;: &amp;quot;http://example.org/predicates/relatesSomehowTo&amp;quot;, &amp;quot;object&amp;quot;: &amp;quot;http://example.org/documents/thatDoc&amp;quot;}&amp;lt;/code&amp;gt;&lt;br /&gt;
*&#039;&#039;&#039;RDF abstract links&#039;&#039;&#039; to other abstract concepts, such as &amp;lt;br&amp;gt;&amp;lt;code&amp;gt;{&amp;quot;subject&amp;quot;: &amp;quot;http://example.org/documents/thisDoc&amp;quot;, &amp;quot;predicate&amp;quot;: &amp;quot;http://example.org/predicates/relatesSomehowTo&amp;quot;, &amp;quot;object&amp;quot;: &amp;quot;http://example.org/documents/someConceptWithNoDocumentAtTheURI&amp;quot;}&amp;lt;/code&amp;gt;&lt;br /&gt;
*&#039;&#039;&#039;RDF data links&#039;&#039;&#039; to data, such as &amp;lt;br&amp;gt;&amp;lt;code&amp;gt;{&amp;quot;subject&amp;quot;: &amp;quot;http://example.org/documents/thisDoc&amp;quot;, &amp;quot;predicate&amp;quot;: &amp;quot;http://example.org/predicates/ageInYears&amp;quot;, &amp;quot;object&amp;quot;: 12}&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
MarkLogic can combine any of these indexes in any way to find matching documents.  It can sort the result by relevance or by value. &lt;br /&gt;
&lt;br /&gt;
The [[MarkLogic Query and Search]] page provides more detail about how MarkLogic&#039;s unique indexes work and how they work together.&lt;br /&gt;
&lt;br /&gt;
[[Categories: MarkLogic]]&lt;/div&gt;</summary>
		<author><name>Bowersmt</name></author>
	</entry>
	<entry>
		<id>https://tech.churchofjesuschrist.org/wiki/index.php?title=MarkLogic&amp;diff=70548</id>
		<title>MarkLogic</title>
		<link rel="alternate" type="text/html" href="https://tech.churchofjesuschrist.org/wiki/index.php?title=MarkLogic&amp;diff=70548"/>
		<updated>2014-11-14T08:15:38Z</updated>

		<summary type="html">&lt;p&gt;Bowersmt: Fixed category to MarkLogic&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== MarkLogic ==&lt;br /&gt;
This is the landing page for MarkLogic.  MarkLogic is an all-in-one application server, document database, and search engine.  It is entirely based on REST. For an extensive explanation of what MarkLogic is and what it can do, see [[What is MarkLogic?]]&lt;br /&gt;
&lt;br /&gt;
== Links to other MarkLogic Documents ==&lt;br /&gt;
* [[What is MarkLogic?]]&lt;br /&gt;
* [[Installing MarkLogic]]&lt;br /&gt;
* [[MarkLogic Training Resources]]&lt;br /&gt;
&lt;br /&gt;
[[Categories: MarkLogic]]&lt;/div&gt;</summary>
		<author><name>Bowersmt</name></author>
	</entry>
	<entry>
		<id>https://tech.churchofjesuschrist.org/wiki/index.php?title=MarkLogic_Query_and_Search&amp;diff=70547</id>
		<title>MarkLogic Query and Search</title>
		<link rel="alternate" type="text/html" href="https://tech.churchofjesuschrist.org/wiki/index.php?title=MarkLogic_Query_and_Search&amp;diff=70547"/>
		<updated>2014-11-14T08:14:26Z</updated>

		<summary type="html">&lt;p&gt;Bowersmt: Indented a line&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== MarkLogic Query and Search ==&lt;br /&gt;
Indexes are central to everything you do in MarkLogic.  They are central to how MarkLogic stores data, scales massively, and processes data quickly. They are central to how you develop because you have to use MarkLogic&#039;s indexes to query and search documents. You have to understand how MarkLogic&#039;s indexes work to be able to create fast queries. And you have to know how to model document structure to work best with indexes.&lt;br /&gt;
&lt;br /&gt;
=== How does MarkLogic compare to a relational database? ===&lt;br /&gt;
A document in MarkLogic is very much like a row in a relational database, and a document type ties documents together like a table ties rows together. Both use indexes to resolve queries without having to scan through rows or documents.&lt;br /&gt;
&lt;br /&gt;
Unlike relational databases, MarkLogic can&#039;t do full table scans; queries must use indexes. In contrast, relational databases often use a full table scan to retrieve every row in a table. A rule of thumb in relational databases is that it is faster to directly read in &#039;&#039;all&#039;&#039; the rows when a query accesses more than roughly 25% of the rows. This is because relational databases use variations of the B-Tree index, which requires 3-4 random IOs to find one row and 1 IO to retrieve the row: this is 4-5 total IOs per row.  B-Tree indexes work best for single row lookups, but they become increasingly costly the more rows they retrieve. If an index has to lookup 25% of its rows with 4 IOs per row, the database will do the same amount of IO if it reads in all of the rows (1 IO per row). Since sequential IO on disks is faster than random IO, relational databases prefer full table scans when accessing more than about 25% of rows in a table. On analytical data warehouses, full table scans are always preferred.  &lt;br /&gt;
&lt;br /&gt;
In addition, a relational database [https://docs.oracle.com/database/121/TGSQL/tgsql_optop.htm#TGSQL234 often directly scans through index data] rather than stepping through its B-Tree structure. Databases use a variety of index scans: full scans, range scans, skip scans, join scans, etc. This is index and table records are stored sequentially on disk. This often makes it faster to take advantage of the speed of sequential disk IO and directly load all index or table rows into RAM and process them in RAM; as opposed to walking a b-tree structure and doing multiple slow random IOs to retrieve each record. For the same reason, row and index scans work well in columnar NoSQL databases.&lt;br /&gt;
&lt;br /&gt;
=== Why do MarkLogic queries have to use Indexes? ===&lt;br /&gt;
To maximize parallelism and to spread processing throughout a cluster, MarkLogic spreads documents across the cluster. MarkLogic automatically creates multiple shards per server and spreads them across all the servers in the cluster. Documents are placed in a shard in the order they are created or modified; thus, documents of all types may be randomly intermixed in a shard. Since a shard is not organized by document type, doing a sequential scan to resolve a query would require retrieving and processing all documents in the database. Full scans are not practical in MarkLogic. All queries and searches need to use indexes. For this reason, MarkLogic automatically indexes almost everything. You can also create additional specialized indexes.  MarkLogic indexes are not B-Tree indexes; they are designed to be sharded and queried in parallel across stands, forests, and a database cluster that spans many servers.&lt;br /&gt;
&lt;br /&gt;
=== How does MarkLogic scale horizontally? ===&lt;br /&gt;
Documents in MarkLogic belong to a database. Within a database are one or more servers.  Each server may contain zero or more &amp;quot;forests&amp;quot;. Within each forest are one or more &amp;quot;stands&amp;quot;. Within each stand are one or more &amp;quot;trees&amp;quot;. A document is hierarchical so it is called a &amp;quot;tree&amp;quot;.  (MarkLogic uses the terms &amp;quot;stand&amp;quot; and &amp;quot;forest&amp;quot; instead of &amp;quot;shard&amp;quot;, but they have the same meaning.) &lt;br /&gt;
&lt;br /&gt;
A client contacts one of the servers in a MarkLogic cluster and initiates a query or search. Because MarkLogic communicates through REST web services, a load balancer can spread requests across the servers in a MarkLogic cluster.  The initiating server does the following&lt;br /&gt;
#it validates the query request from the client&lt;br /&gt;
#it parses and optimizes the query &lt;br /&gt;
#it sends the query to all servers that have forests in the database&lt;br /&gt;
##each server sends it to its forests &lt;br /&gt;
##each forest sends it to each stand &lt;br /&gt;
##each stand uses its indexes to find matching documents&lt;br /&gt;
###all stands and forests query the indexes in parallel&lt;br /&gt;
##forests combine the matching document IDs from all their stands&lt;br /&gt;
##forests sort the matching document IDs (in relevance score order or value order)&lt;br /&gt;
##when complete, each forest returns a sorted iterator to the initiating server&lt;br /&gt;
#when each forest has returned an iterator&lt;br /&gt;
#it walks the sorted iterators from all the forests and combines the results in sorted &lt;br /&gt;
#it retrieves matching documents from its &#039;&#039;Expanded Tree Cache&#039;&#039; or from the forests when documents are not cached&lt;br /&gt;
##forests retrieve documents from their &#039;&#039;Compressed Tree Cache&#039;&#039; or from disk when documents are not cached&lt;br /&gt;
#it filters returned documents to remove false positive matches &lt;br /&gt;
#it optionally transforms documents &lt;br /&gt;
##it creates new documents by extracting matching elements, changing structure, changing file format, etc.&lt;br /&gt;
#it returns all matching (optionally transformed) documents to the requester&lt;br /&gt;
#it saves resulting document IDs when paging query results, so it can return subsequent pages of matching documents in subsequent requests&lt;br /&gt;
&lt;br /&gt;
The initiating server&#039;s process is CPU intensive, serialized, and blocks while waiting on forests. To prevent this from being a bottleneck to the cluster, you can dedicate nodes in the cluster to do nothing but evaluate queries. These are called e-nodes (evaluation nodes). These nodes don&#039;t hold data. If they held data, the &#039;&#039;serialized&#039;&#039; evaluation process would compete with the &#039;&#039;parallel&#039;&#039; index matching process.  Instead e-nodes are dedicated to validating, parsing, sorting, filtering, transforming, and paginating documents. They cache documents in the &#039;&#039;Expanded Tree Cache&#039;&#039; to minimize the number of documents they have to retrieve from data nodes (d-nodes). D-nodes only do parallel index processing and sorting. They cache documents in their &#039;&#039;Compressed Tree Cache&#039;&#039; to reduce disk IO. &lt;br /&gt;
&lt;br /&gt;
=== How do you optimize a MarkLogic cluster to run queries faster? ===&lt;br /&gt;
*E-nodes and d-nodes can be scaled independently to match the load. &lt;br /&gt;
*You can optimize an e-node by minimizing its &#039;&#039;Compressed Tree Cache&#039;&#039; and maximizing its &#039;&#039;Expanded Tree Cache&#039;&#039;. An e-node needs a big &#039;&#039;Expanded Tree Cache&#039;&#039; so it doesn&#039;t have to retrieve as many documents from d-nodes. An e-node doesn&#039;t need a &#039;&#039;Compressed Tree Cache&#039;&#039; because it doesn&#039;t have any data.&lt;br /&gt;
*You can optimize a d-node by doing the opposite of the e-node: maximize the &#039;&#039;Compressed Tree Cache&#039;&#039; and minimize the &#039;&#039;Expanded Tree Cache&#039;&#039;. You can also optimize d-nodes by making sure each d-node runs on similar hardware and that each forest has a similar number of documents. This is important because all forests process queries in parallel and the slowest forest holds up each query: e-nodes have to wait until the slowest forest finishes.&lt;br /&gt;
*You can optimize a query by making it unfiltered.&lt;br /&gt;
**This means it is completely resolved by the indexes. Because no filtering is required, the initiating server doesn&#039;t have to verify that documents match.&lt;br /&gt;
*You can optimize a query by eliminating false positives.  &lt;br /&gt;
**False positives occur when a query identifies a possible match for a document, but it cannot prove it is a match until the filtering process opens the document and verifies it. &lt;br /&gt;
**False positives happen because MarkLogic only partially indexes certain document items. MarkLogic cannot index everything because it would take too much time and space. For example, MarkLogic has a structure index. It indexes relationships between elements in a document.  MarkLogic cannot afford to index each element&#039;s path from itself to every other element. MarkLogic compromises on indexing only parent/child relationships. This is effective in eliminating most non-matching documents, but it can produce false positives.  The only way to know if a document is an &#039;&#039;exact&#039;&#039; match, MarkLogic must open the document and verify it.&lt;br /&gt;
**For example, suppose a query searches for the following path: &amp;lt;br&amp;gt;&amp;lt;code&amp;gt;books/poetry/poem&amp;lt;/code&amp;gt;&amp;lt;br&amp;gt; The structure index will match documents containing books/poetry and poetry/poem. The resulting documents are a probable match, but could contain false positives, such as &amp;lt;br&amp;gt;&amp;lt;code&amp;gt;books/poetry/fantasy/poetry/poem&amp;lt;/code&amp;gt;.&lt;br /&gt;
**You can eliminate false positive structures queries by giving elements unique names. They are  unique no matter where in they are in the structure and they are more self-descriptive.  Instead of naming an element &amp;quot;line&amp;quot; which can mean many things, you can use the precise name  &amp;quot;poemTextLine&amp;quot;. &lt;br /&gt;
*You can optimize a query by greatly limiting how many documents it matches. Design each query to return as few documents as possible. &lt;br /&gt;
**It is expensive to transmit documents. Matching documents have to travel from stands to forests to the initiating server, and to the requester. &lt;br /&gt;
**It is expensive to process documents on the initiating server and the requester. &lt;br /&gt;
**It takes processing time on d-nodes to compare lists of document IDs. The fewer the matching document IDs in one part of the query, the faster the entire query runs. &lt;br /&gt;
**The more matching document IDs, the more work MarkLogic has to do in a d-node to compare, union, intersect, and subract them from matching document IDs returned by other parts of the query. &lt;br /&gt;
**The more matching document IDs, the more sorting MarkLogic has to do in the stands, forests, and initiating server.&lt;br /&gt;
&lt;br /&gt;
=== How does a MarkLogic query compare to map/reduce? ===&lt;br /&gt;
A MarkLogic query or search is similar to map/reduce.  When you query or search for documents in a database, MarkLogic spreads the work across all the servers to be executed in parallel. This is like a &#039;&#039;map&#039;&#039; process because indexes filter out non-matching documents by combining term, range, and semantic indexes according to the query map. The results are then &#039;&#039;reduced&#039;&#039; at the forest level and again at the database level and again at the initiating server. This parallel division of responsibilities enables MarkLogic to scale.&lt;br /&gt;
&lt;br /&gt;
== Term, Range, and Semantic Indexes ==&lt;br /&gt;
MarkLogic indexes are not B-Tree indexes. MarkLogic uses &#039;&#039;&#039;term&#039;&#039;&#039;, &#039;&#039;&#039;range&#039;&#039;&#039;, and &#039;&#039;&#039;semantic&#039;&#039;&#039; indexes. &lt;br /&gt;
*&#039;&#039;&#039;A term index&#039;&#039;&#039; associates a term with every document that contains the term.  For example, in a word index, every word in the database is stored in the index. Associated with each word in the index is a list of each document ID that contains the term.  &lt;br /&gt;
*&#039;&#039;&#039;A range index&#039;&#039;&#039; is a double term index: it contains each term and all document IDs that contain that term, and it contains each document ID and all the terms that are in the document.&lt;br /&gt;
*&#039;&#039;&#039;A semantic index&#039;&#039;&#039; is similar to a range index but it is optimized to store triples (three pieces of data: subject, object, and predicate).&lt;br /&gt;
&lt;br /&gt;
Term indexes are fast. Give the index a term, and with one lookup, it returns &#039;&#039;all&#039;&#039; documents that contain the term. Term indexes are memory mapped files. They run in RAM unless you run out of RAM and then firmware in the CPU efficiently swaps them to and from disk. Thus, it is best to have enough RAM in a MarkLogic server to contain all indexes in memory.&lt;br /&gt;
&lt;br /&gt;
Unlike B-Tree indexes, term indexes are easily sharded within and between servers. MarkLogic takes advantage of this to run queries in parallel within and across servers. This is how MarkLogic can scale to billions of documents and still return queries and searches in milliseconds.&lt;br /&gt;
&lt;br /&gt;
When documents are inserted or updated, MarkLogic indexes them in RAM (as well as appends the changes to a journal on disk). When documents in RAM start to consume too much RAM, MarkLogic writes them to disk as a &amp;quot;stand&amp;quot; in a &amp;quot;forest&amp;quot; and starts creating a new &amp;quot;stand&amp;quot; in RAM.  &lt;br /&gt;
&lt;br /&gt;
When you query or search for documents, MarkLogic goes to the indexes in the stands (which are cached in RAM) and evaluates the query in parallel. Each stand index returns a list of document IDs (a list of numbers) that match the query. MarkLogic takes the document IDs returned by each stand and merges them into a final list of document IDs, whcih it uses to retrieve the documents from cache or disk. This works well because computers are very fast at sort merging lists of numbers.&lt;br /&gt;
&lt;br /&gt;
MarkLogic uses the same indexes for both queries and searches. This allows you to combine search and query expressions. The main difference between search and query is how documents are sorted: searches sort by relevance and queries sort by values. Another difference is that queries tend to use value indexes and searches tend to use word and phrase indexes. &lt;br /&gt;
&lt;br /&gt;
=== What specific indexes does MarkLogic have? ===&lt;br /&gt;
MarkLogic uses indexes to extract words, values, structures, and links out of documents. An index is an altered view of a document. It enables you to search and query for documents &amp;lt;br&amp;gt;&#039;&#039;&#039;as if they contained only:&#039;&#039;&#039;&lt;br /&gt;
*&#039;&#039;&#039;Words:&#039;&#039;&#039; a flat set of words without structure, such as &amp;lt;br&amp;gt;&amp;lt;code&amp;gt;[&amp;quot;Mary&amp;quot;, &amp;quot;had&amp;quot;, &amp;quot;a&amp;quot;, &amp;quot;little&amp;quot;, &amp;quot;lamb&amp;quot;]&amp;lt;/code&amp;gt;&lt;br /&gt;
*&#039;&#039;&#039;Phrases:&#039;&#039;&#039; a flat set of phrases without structure, such as &amp;lt;br&amp;gt;&amp;lt;code&amp;gt;[&amp;quot;Mary had&amp;quot;, &amp;quot;had a&amp;quot;, &amp;quot;a little&amp;quot;, &amp;quot;little lamb&amp;quot;]&amp;lt;/code&amp;gt;&lt;br /&gt;
*&#039;&#039;&#039;Elements:&#039;&#039;&#039; a flat set of elements without values, such as &amp;lt;br&amp;gt;&amp;lt;code&amp;gt;[&amp;quot;poem&amp;quot;, &amp;quot;text&amp;quot;, &amp;quot;line&amp;quot;]&amp;lt;/code&amp;gt;&lt;br /&gt;
*&#039;&#039;&#039;Element-values:&#039;&#039;&#039; a flat set of elements with string values, such as &amp;lt;br&amp;gt;&amp;lt;code&amp;gt;&amp;quot;line&amp;quot;: &amp;quot;Mary had a little lamb&amp;quot;&amp;lt;/code&amp;gt;&lt;br /&gt;
*&#039;&#039;&#039;Element-words:&#039;&#039;&#039; a flat set of elements with words, such as &amp;lt;br&amp;gt;&amp;lt;code&amp;gt;&amp;quot;line&amp;quot;: [&amp;quot;Mary&amp;quot;, &amp;quot;had&amp;quot;, &amp;quot;a&amp;quot;, &amp;quot;little&amp;quot;, &amp;quot;lamb&amp;quot;]&amp;lt;/code&amp;gt;&lt;br /&gt;
*&#039;&#039;&#039;Element-phrases:&#039;&#039;&#039; a flat set of elements with phrases, such as &amp;lt;br&amp;gt;&amp;lt;code&amp;gt;&amp;quot;line&amp;quot;: [&amp;quot;Mary had&amp;quot;, &amp;quot;had a&amp;quot;, &amp;quot;a little&amp;quot;, &amp;quot;little lamb&amp;quot;]&amp;lt;/code&amp;gt;&lt;br /&gt;
*&#039;&#039;&#039;Element-value lexicon:&#039;&#039;&#039; a flat set of elements with typed values, such as &amp;lt;br&amp;gt;&amp;lt;code&amp;gt;&amp;quot;lineSequence&amp;quot;: 3&amp;lt;/code&amp;gt;&amp;lt;br&amp;gt; or a list, count, or co-occurrence of element values scoped to a database, set of documents, or one document.&lt;br /&gt;
*&#039;&#039;&#039;XPath-structure-value lexicon:&#039;&#039;&#039; a flat set of hierarchical elements with typed values, such as &amp;lt;br&amp;gt;&amp;lt;code&amp;gt;poem.text.line.lineSequence: 3&amp;lt;/code&amp;gt;&amp;lt;br&amp;gt; or a list, count, or co-occurrence of hierarchical element values scoped to a database, set of documents, or one document.&lt;br /&gt;
*&#039;&#039;&#039;XPath-structure:&#039;&#039;&#039;hierarchical structures without values, such as &amp;lt;br&amp;gt;&amp;lt;code&amp;gt;poem.text.line&amp;lt;/code&amp;gt;&lt;br /&gt;
*&#039;&#039;&#039;XPath-structure-words:&#039;&#039;&#039; hierarchical structures with words, such as &amp;lt;br&amp;gt;&amp;lt;code&amp;gt;poem.text.line: [&amp;quot;Mary&amp;quot;, &amp;quot;had&amp;quot;, &amp;quot;a&amp;quot;, &amp;quot;little&amp;quot;, &amp;quot;lamb&amp;quot;]&amp;lt;/code&amp;gt;&lt;br /&gt;
*&#039;&#039;&#039;XPath-structure-phrases:&#039;&#039;&#039; hierarchical structures with phrases, such as &amp;lt;br&amp;gt;&amp;lt;code&amp;gt;poem.text.line: [&amp;quot;Mary had&amp;quot;, &amp;quot;had a&amp;quot;, &amp;quot;a little&amp;quot;, &amp;quot;little lamb&amp;quot;]&amp;lt;/code&amp;gt;&lt;br /&gt;
*&#039;&#039;&#039;XPath-structure-values:&#039;&#039;&#039; hierarchical structures with values, such as &amp;lt;br&amp;gt;&amp;lt;code&amp;gt;poem.text.line: &amp;quot;Mary had a little lamb&amp;quot;&amp;lt;/code&amp;gt;&lt;br /&gt;
*&#039;&#039;&#039;RDF document links&#039;&#039;&#039; to other documents, such as &amp;lt;br&amp;gt;&amp;lt;code&amp;gt;{&amp;quot;subject&amp;quot;: &amp;quot;http://example.org/documents/thisDoc&amp;quot;, &amp;lt;br&amp;gt;&amp;quot;predicate&amp;quot;: &amp;quot;http://example.org/predicates/relatesSomehowTo&amp;quot;, &amp;lt;br&amp;gt;&amp;quot;object&amp;quot;: &amp;quot;http://example.org/documents/thatDoc&amp;quot;}&amp;lt;/code&amp;gt;&lt;br /&gt;
*&#039;&#039;&#039;RDF abstract links&#039;&#039;&#039; to other abstract concepts, such as &amp;lt;br&amp;gt;&amp;lt;code&amp;gt;{&amp;quot;subject&amp;quot;: &amp;quot;http://example.org/documents/thisDoc&amp;quot;, &amp;lt;br&amp;gt;&amp;quot;predicate&amp;quot;: &amp;quot;http://example.org/predicates/relatesSomehowTo&amp;quot;, &amp;lt;br&amp;gt;&amp;quot;object&amp;quot;: &amp;quot;http://example.org/documents/someConceptWithNoDocumentAtTheURI&amp;quot;}&amp;lt;/code&amp;gt;&lt;br /&gt;
*&#039;&#039;&#039;RDF data links&#039;&#039;&#039; to data, such as &amp;lt;br&amp;gt;&amp;lt;code&amp;gt;{&amp;quot;subject&amp;quot;: &amp;quot;http://example.org/documents/thisDoc&amp;quot;, &amp;lt;br&amp;gt;&amp;quot;predicate&amp;quot;: &amp;quot;http://example.org/predicates/ageInYears&amp;quot;, &amp;lt;br&amp;gt;&amp;quot;object&amp;quot;: 12}&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
MarkLogic can combine any of these indexes in any way to find matching documents.  It can sort the result by relevance or by value. &lt;br /&gt;
&lt;br /&gt;
Search and query expressions are fully composable; i.e. they can be nested inside each other and combined using AND, OR, and NOT expressions.&lt;br /&gt;
&lt;br /&gt;
== Training Resources for MarkLogic Search ==&lt;br /&gt;
* [http://developer.marklogic.com/blog/grokking-the-cts-api &amp;quot;Grokking the cts API&amp;quot;] is a great overview of MarkLogic&#039;s search and query capabilities.&lt;br /&gt;
&lt;br /&gt;
[[Categories: MarkLogic]]&lt;/div&gt;</summary>
		<author><name>Bowersmt</name></author>
	</entry>
	<entry>
		<id>https://tech.churchofjesuschrist.org/wiki/index.php?title=MarkLogic_Query_and_Search&amp;diff=70546</id>
		<title>MarkLogic Query and Search</title>
		<link rel="alternate" type="text/html" href="https://tech.churchofjesuschrist.org/wiki/index.php?title=MarkLogic_Query_and_Search&amp;diff=70546"/>
		<updated>2014-11-14T08:12:50Z</updated>

		<summary type="html">&lt;p&gt;Bowersmt: Created&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== MarkLogic Query and Search ==&lt;br /&gt;
Indexes are central to everything you do in MarkLogic.  They are central to how MarkLogic stores data, scales massively, and processes data quickly. They are central to how you develop because you have to use MarkLogic&#039;s indexes to query and search documents. You have to understand how MarkLogic&#039;s indexes work to be able to create fast queries. And you have to know how to model document structure to work best with indexes.&lt;br /&gt;
&lt;br /&gt;
=== How does MarkLogic compare to a relational database? ===&lt;br /&gt;
A document in MarkLogic is very much like a row in a relational database, and a document type ties documents together like a table ties rows together. Both use indexes to resolve queries without having to scan through rows or documents.&lt;br /&gt;
&lt;br /&gt;
Unlike relational databases, MarkLogic can&#039;t do full table scans; queries must use indexes. In contrast, relational databases often use a full table scan to retrieve every row in a table. A rule of thumb in relational databases is that it is faster to directly read in &#039;&#039;all&#039;&#039; the rows when a query accesses more than roughly 25% of the rows. This is because relational databases use variations of the B-Tree index, which requires 3-4 random IOs to find one row and 1 IO to retrieve the row: this is 4-5 total IOs per row.  B-Tree indexes work best for single row lookups, but they become increasingly costly the more rows they retrieve. If an index has to lookup 25% of its rows with 4 IOs per row, the database will do the same amount of IO if it reads in all of the rows (1 IO per row). Since sequential IO on disks is faster than random IO, relational databases prefer full table scans when accessing more than about 25% of rows in a table. On analytical data warehouses, full table scans are always preferred.  &lt;br /&gt;
&lt;br /&gt;
In addition, a relational database [https://docs.oracle.com/database/121/TGSQL/tgsql_optop.htm#TGSQL234 often directly scans through index data] rather than stepping through its B-Tree structure. Databases use a variety of index scans: full scans, range scans, skip scans, join scans, etc. This is index and table records are stored sequentially on disk. This often makes it faster to take advantage of the speed of sequential disk IO and directly load all index or table rows into RAM and process them in RAM; as opposed to walking a b-tree structure and doing multiple slow random IOs to retrieve each record. For the same reason, row and index scans work well in columnar NoSQL databases.&lt;br /&gt;
&lt;br /&gt;
=== Why do MarkLogic queries have to use Indexes? ===&lt;br /&gt;
To maximize parallelism and to spread processing throughout a cluster, MarkLogic spreads documents across the cluster. MarkLogic automatically creates multiple shards per server and spreads them across all the servers in the cluster. Documents are placed in a shard in the order they are created or modified; thus, documents of all types may be randomly intermixed in a shard. Since a shard is not organized by document type, doing a sequential scan to resolve a query would require retrieving and processing all documents in the database. Full scans are not practical in MarkLogic. All queries and searches need to use indexes. For this reason, MarkLogic automatically indexes almost everything. You can also create additional specialized indexes.  MarkLogic indexes are not B-Tree indexes; they are designed to be sharded and queried in parallel across stands, forests, and a database cluster that spans many servers.&lt;br /&gt;
&lt;br /&gt;
=== How does MarkLogic scale horizontally? ===&lt;br /&gt;
Documents in MarkLogic belong to a database. Within a database are one or more servers.  Each server may contain zero or more &amp;quot;forests&amp;quot;. Within each forest are one or more &amp;quot;stands&amp;quot;. Within each stand are one or more &amp;quot;trees&amp;quot;. A document is hierarchical so it is called a &amp;quot;tree&amp;quot;.  (MarkLogic uses the terms &amp;quot;stand&amp;quot; and &amp;quot;forest&amp;quot; instead of &amp;quot;shard&amp;quot;, but they have the same meaning.) &lt;br /&gt;
&lt;br /&gt;
A client contacts one of the servers in a MarkLogic cluster and initiates a query or search. Because MarkLogic communicates through REST web services, a load balancer can spread requests across the servers in a MarkLogic cluster.  The initiating server does the following&lt;br /&gt;
#it validates the query request from the client&lt;br /&gt;
#it parses and optimizes the query &lt;br /&gt;
#it sends the query to all servers that have forests in the database&lt;br /&gt;
##each server sends it to its forests &lt;br /&gt;
##each forest sends it to each stand &lt;br /&gt;
##each stand uses its indexes to find matching documents&lt;br /&gt;
###all stands and forests query the indexes in parallel&lt;br /&gt;
##forests combine the matching document IDs from all their stands&lt;br /&gt;
##forests sort the matching document IDs (in relevance score order or value order)&lt;br /&gt;
##when complete, each forest returns a sorted iterator to the initiating server&lt;br /&gt;
#when each forest has returned an iterator&lt;br /&gt;
#it walks the sorted iterators from all the forests and combines the results in sorted &lt;br /&gt;
#it retrieves matching documents from its &#039;&#039;Expanded Tree Cache&#039;&#039; or from the forests when documents are not cached&lt;br /&gt;
##forests retrieve documents from their &#039;&#039;Compressed Tree Cache&#039;&#039; or from disk when documents are not cached&lt;br /&gt;
#it filters returned documents to remove false positive matches &lt;br /&gt;
#it optionally transforms documents &lt;br /&gt;
##it creates new documents by extracting matching elements, changing structure, changing file format, etc.&lt;br /&gt;
#it returns all matching (optionally transformed) documents to the requester&lt;br /&gt;
#it saves resulting document IDs when paging query results, so it can return subsequent pages of matching documents in subsequent requests&lt;br /&gt;
&lt;br /&gt;
The initiating server&#039;s process is CPU intensive, serialized, and blocks while waiting on forests. To prevent this from being a bottleneck to the cluster, you can dedicate nodes in the cluster to do nothing but evaluate queries. These are called e-nodes (evaluation nodes). These nodes don&#039;t hold data. If they held data, the &#039;&#039;serialized&#039;&#039; evaluation process would compete with the &#039;&#039;parallel&#039;&#039; index matching process.  Instead e-nodes are dedicated to validating, parsing, sorting, filtering, transforming, and paginating documents. They cache documents in the &#039;&#039;Expanded Tree Cache&#039;&#039; to minimize the number of documents they have to retrieve from data nodes (d-nodes). D-nodes only do parallel index processing and sorting. They cache documents in their &#039;&#039;Compressed Tree Cache&#039;&#039; to reduce disk IO. &lt;br /&gt;
&lt;br /&gt;
=== How do you optimize a MarkLogic cluster to run queries faster? ===&lt;br /&gt;
*E-nodes and d-nodes can be scaled independently to match the load. &lt;br /&gt;
*You can optimize an e-node by minimizing its &#039;&#039;Compressed Tree Cache&#039;&#039; and maximizing its &#039;&#039;Expanded Tree Cache&#039;&#039;. An e-node needs a big &#039;&#039;Expanded Tree Cache&#039;&#039; so it doesn&#039;t have to retrieve as many documents from d-nodes. An e-node doesn&#039;t need a &#039;&#039;Compressed Tree Cache&#039;&#039; because it doesn&#039;t have any data.&lt;br /&gt;
*You can optimize a d-node by doing the opposite of the e-node: maximize the &#039;&#039;Compressed Tree Cache&#039;&#039; and minimize the &#039;&#039;Expanded Tree Cache&#039;&#039;. You can also optimize d-nodes by making sure each d-node runs on similar hardware and that each forest has a similar number of documents. This is important because all forests process queries in parallel and the slowest forest holds up each query: e-nodes have to wait until the slowest forest finishes.&lt;br /&gt;
*You can optimize a query by making it unfiltered.&lt;br /&gt;
**This means it is completely resolved by the indexes. Because no filtering is required, the initiating server doesn&#039;t have to verify that documents match.&lt;br /&gt;
*You can optimize a query by eliminating false positives.  &lt;br /&gt;
**False positives occur when a query identifies a possible match for a document, but it cannot prove it is a match until the filtering process opens the document and verifies it. &lt;br /&gt;
**False positives happen because MarkLogic only partially indexes certain document items. MarkLogic cannot index everything because it would take too much time and space. For example, MarkLogic has a structure index. It indexes relationships between elements in a document.  MarkLogic cannot afford to index each element&#039;s path from itself to every other element. MarkLogic compromises on indexing only parent/child relationships. This is effective in eliminating most non-matching documents, but it can produce false positives.  The only way to know if a document is an &#039;&#039;exact&#039;&#039; match, MarkLogic must open the document and verify it.&lt;br /&gt;
**For example, suppose a query searches for the following path: &amp;lt;br&amp;gt;&amp;lt;code&amp;gt;books/poetry/poem&amp;lt;/code&amp;gt;&amp;lt;br&amp;gt; The structure index will match documents containing books/poetry and poetry/poem. The resulting documents are a probable match, but could contain false positives, such as &amp;lt;br&amp;gt;&amp;lt;code&amp;gt;books/poetry/fantasy/poetry/poem&amp;lt;/code&amp;gt;.&lt;br /&gt;
**You can eliminate false positive structures queries by giving elements unique names. They are  unique no matter where in they are in the structure and they are more self-descriptive.  Instead of naming an element &amp;quot;line&amp;quot; which can mean many things, you can use the precise name  &amp;quot;poemTextLine&amp;quot;. &lt;br /&gt;
*You can optimize a query by greatly limiting how many documents it matches. Design each query to return as few documents as possible. &lt;br /&gt;
**It is expensive to transmit documents. Matching documents have to travel from stands to forests to the initiating server, and to the requester. &lt;br /&gt;
**It is expensive to process documents on the initiating server and the requester. &lt;br /&gt;
**It takes processing time on d-nodes to compare lists of document IDs. The fewer the matching document IDs in one part of the query, the faster the entire query runs. &lt;br /&gt;
**The more matching document IDs, the more work MarkLogic has to do in a d-node to compare, union, intersect, and subract them from matching document IDs returned by other parts of the query. &lt;br /&gt;
**The more matching document IDs, the more sorting MarkLogic has to do in the stands, forests, and initiating server.&lt;br /&gt;
&lt;br /&gt;
=== How does a MarkLogic query compare to map/reduce? ===&lt;br /&gt;
A MarkLogic query or search is similar to map/reduce.  When you query or search for documents in a database, MarkLogic spreads the work across all the servers to be executed in parallel. This is like a &#039;&#039;map&#039;&#039; process because indexes filter out non-matching documents by combining term, range, and semantic indexes according to the query map. The results are then &#039;&#039;reduced&#039;&#039; at the forest level and again at the database level and again at the initiating server. This parallel division of responsibilities enables MarkLogic to scale.&lt;br /&gt;
&lt;br /&gt;
== Term, Range, and Semantic Indexes ==&lt;br /&gt;
MarkLogic indexes are not B-Tree indexes. MarkLogic uses &#039;&#039;&#039;term&#039;&#039;&#039;, &#039;&#039;&#039;range&#039;&#039;&#039;, and &#039;&#039;&#039;semantic&#039;&#039;&#039; indexes. &lt;br /&gt;
*&#039;&#039;&#039;A term index&#039;&#039;&#039; associates a term with every document that contains the term.  For example, in a word index, every word in the database is stored in the index. Associated with each word in the index is a list of each document ID that contains the term.  &lt;br /&gt;
*&#039;&#039;&#039;A range index&#039;&#039;&#039; is a double term index: it contains each term and all document IDs that contain that term, and it contains each document ID and all the terms that are in the document.&lt;br /&gt;
*&#039;&#039;&#039;A semantic index&#039;&#039;&#039; is similar to a range index but it is optimized to store triples (three pieces of data: subject, object, and predicate).&lt;br /&gt;
&lt;br /&gt;
Term indexes are fast. Give the index a term, and with one lookup, it returns &#039;&#039;all&#039;&#039; documents that contain the term. Term indexes are memory mapped files. They run in RAM unless you run out of RAM and then firmware in the CPU efficiently swaps them to and from disk. Thus, it is best to have enough RAM in a MarkLogic server to contain all indexes in memory.&lt;br /&gt;
&lt;br /&gt;
Unlike B-Tree indexes, term indexes are easily sharded within and between servers. MarkLogic takes advantage of this to run queries in parallel within and across servers. This is how MarkLogic can scale to billions of documents and still return queries and searches in milliseconds.&lt;br /&gt;
&lt;br /&gt;
When documents are inserted or updated, MarkLogic indexes them in RAM (as well as appends the changes to a journal on disk). When documents in RAM start to consume too much RAM, MarkLogic writes them to disk as a &amp;quot;stand&amp;quot; in a &amp;quot;forest&amp;quot; and starts creating a new &amp;quot;stand&amp;quot; in RAM.  &lt;br /&gt;
&lt;br /&gt;
When you query or search for documents, MarkLogic goes to the indexes in the stands (which are cached in RAM) and evaluates the query in parallel. Each stand index returns a list of document IDs (a list of numbers) that match the query. MarkLogic takes the document IDs returned by each stand and merges them into a final list of document IDs, whcih it uses to retrieve the documents from cache or disk. This works well because computers are very fast at sort merging lists of numbers.&lt;br /&gt;
&lt;br /&gt;
MarkLogic uses the same indexes for both queries and searches. This allows you to combine search and query expressions. The main difference between search and query is how documents are sorted: searches sort by relevance and queries sort by values. Another difference is that queries tend to use value indexes and searches tend to use word and phrase indexes. &lt;br /&gt;
&lt;br /&gt;
== What specific indexes does MarkLogic have? ==&lt;br /&gt;
MarkLogic uses indexes to extract words, values, structures, and links out of documents. An index is an altered view of a document. It enables you to search and query for documents &amp;lt;br&amp;gt;&#039;&#039;&#039;as if they contained only:&#039;&#039;&#039;&lt;br /&gt;
*&#039;&#039;&#039;Words:&#039;&#039;&#039; a flat set of words without structure, such as &amp;lt;br&amp;gt;&amp;lt;code&amp;gt;[&amp;quot;Mary&amp;quot;, &amp;quot;had&amp;quot;, &amp;quot;a&amp;quot;, &amp;quot;little&amp;quot;, &amp;quot;lamb&amp;quot;]&amp;lt;/code&amp;gt;&lt;br /&gt;
*&#039;&#039;&#039;Phrases:&#039;&#039;&#039; a flat set of phrases without structure, such as &amp;lt;br&amp;gt;&amp;lt;code&amp;gt;[&amp;quot;Mary had&amp;quot;, &amp;quot;had a&amp;quot;, &amp;quot;a little&amp;quot;, &amp;quot;little lamb&amp;quot;]&amp;lt;/code&amp;gt;&lt;br /&gt;
*&#039;&#039;&#039;Elements:&#039;&#039;&#039; a flat set of elements without values, such as &amp;lt;br&amp;gt;&amp;lt;code&amp;gt;[&amp;quot;poem&amp;quot;, &amp;quot;text&amp;quot;, &amp;quot;line&amp;quot;]&amp;lt;/code&amp;gt;&lt;br /&gt;
*&#039;&#039;&#039;Element-values:&#039;&#039;&#039; a flat set of elements with string values, such as &amp;lt;br&amp;gt;&amp;lt;code&amp;gt;&amp;quot;line&amp;quot;: &amp;quot;Mary had a little lamb&amp;quot;&amp;lt;/code&amp;gt;&lt;br /&gt;
*&#039;&#039;&#039;Element-words:&#039;&#039;&#039; a flat set of elements with words, such as &amp;lt;br&amp;gt;&amp;lt;code&amp;gt;&amp;quot;line&amp;quot;: [&amp;quot;Mary&amp;quot;, &amp;quot;had&amp;quot;, &amp;quot;a&amp;quot;, &amp;quot;little&amp;quot;, &amp;quot;lamb&amp;quot;]&amp;lt;/code&amp;gt;&lt;br /&gt;
*&#039;&#039;&#039;Element-phrases:&#039;&#039;&#039; a flat set of elements with phrases, such as &amp;lt;br&amp;gt;&amp;lt;code&amp;gt;&amp;quot;line&amp;quot;: [&amp;quot;Mary had&amp;quot;, &amp;quot;had a&amp;quot;, &amp;quot;a little&amp;quot;, &amp;quot;little lamb&amp;quot;]&amp;lt;/code&amp;gt;&lt;br /&gt;
*&#039;&#039;&#039;Element-value lexicon:&#039;&#039;&#039; a flat set of elements with typed values, such as &amp;lt;br&amp;gt;&amp;lt;code&amp;gt;&amp;quot;lineSequence&amp;quot;: 3&amp;lt;/code&amp;gt;&amp;lt;br&amp;gt; or a list, count, or co-occurrence of element values scoped to a database, set of documents, or one document.&lt;br /&gt;
*&#039;&#039;&#039;XPath-structure-value lexicon:&#039;&#039;&#039; a flat set of hierarchical elements with typed values, such as &amp;lt;br&amp;gt;&amp;lt;code&amp;gt;poem.text.line.lineSequence: 3&amp;lt;/code&amp;gt;&amp;lt;br&amp;gt; or a list, count, or co-occurrence of hierarchical element values scoped to a database, set of documents, or one document.&lt;br /&gt;
*&#039;&#039;&#039;XPath-structure:&#039;&#039;&#039;hierarchical structures without values, such as &amp;lt;br&amp;gt;&amp;lt;code&amp;gt;poem.text.line&amp;lt;/code&amp;gt;&lt;br /&gt;
*&#039;&#039;&#039;XPath-structure-words:&#039;&#039;&#039; hierarchical structures with words, such as &amp;lt;br&amp;gt;&amp;lt;code&amp;gt;poem.text.line: [&amp;quot;Mary&amp;quot;, &amp;quot;had&amp;quot;, &amp;quot;a&amp;quot;, &amp;quot;little&amp;quot;, &amp;quot;lamb&amp;quot;]&amp;lt;/code&amp;gt;&lt;br /&gt;
*&#039;&#039;&#039;XPath-structure-phrases:&#039;&#039;&#039; hierarchical structures with phrases, such as &amp;lt;br&amp;gt;&amp;lt;code&amp;gt;poem.text.line: [&amp;quot;Mary had&amp;quot;, &amp;quot;had a&amp;quot;, &amp;quot;a little&amp;quot;, &amp;quot;little lamb&amp;quot;]&amp;lt;/code&amp;gt;&lt;br /&gt;
*&#039;&#039;&#039;XPath-structure-values:&#039;&#039;&#039; hierarchical structures with values, such as &amp;lt;br&amp;gt;&amp;lt;code&amp;gt;poem.text.line: &amp;quot;Mary had a little lamb&amp;quot;&amp;lt;/code&amp;gt;&lt;br /&gt;
*&#039;&#039;&#039;RDF document links&#039;&#039;&#039; to other documents, such as &amp;lt;br&amp;gt;&amp;lt;code&amp;gt;{&amp;quot;subject&amp;quot;: &amp;quot;http://example.org/documents/thisDoc&amp;quot;, &amp;lt;br&amp;gt;&amp;quot;predicate&amp;quot;: &amp;quot;http://example.org/predicates/relatesSomehowTo&amp;quot;, &amp;lt;br&amp;gt;&amp;quot;object&amp;quot;: &amp;quot;http://example.org/documents/thatDoc&amp;quot;}&amp;lt;/code&amp;gt;&lt;br /&gt;
*&#039;&#039;&#039;RDF abstract links&#039;&#039;&#039; to other abstract concepts, such as &amp;lt;br&amp;gt;&amp;lt;code&amp;gt;{&amp;quot;subject&amp;quot;: &amp;quot;http://example.org/documents/thisDoc&amp;quot;, &amp;lt;br&amp;gt;&amp;quot;predicate&amp;quot;: &amp;quot;http://example.org/predicates/relatesSomehowTo&amp;quot;, &amp;lt;br&amp;gt;&amp;quot;object&amp;quot;: &amp;quot;http://example.org/documents/someConceptWithNoDocumentAtTheURI&amp;quot;}&amp;lt;/code&amp;gt;&lt;br /&gt;
*&#039;&#039;&#039;RDF data links&#039;&#039;&#039; to data, such as &amp;lt;br&amp;gt;&amp;lt;code&amp;gt;{&amp;quot;subject&amp;quot;: &amp;quot;http://example.org/documents/thisDoc&amp;quot;, &amp;lt;br&amp;gt;&amp;quot;predicate&amp;quot;: &amp;quot;http://example.org/predicates/ageInYears&amp;quot;, &amp;lt;br&amp;gt;&amp;quot;object&amp;quot;: 12}&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
MarkLogic can combine any of these indexes in any way to find matching documents.  It can sort the result by relevance or by value. &lt;br /&gt;
&lt;br /&gt;
Search and query expressions are fully composable; i.e. they can be nested inside each other and combined using AND, OR, and NOT expressions.&lt;br /&gt;
&lt;br /&gt;
== Training Resources for MarkLogic Search ==&lt;br /&gt;
* [http://developer.marklogic.com/blog/grokking-the-cts-api &amp;quot;Grokking the cts API&amp;quot;] is a great overview of MarkLogic&#039;s search and query capabilities.&lt;br /&gt;
&lt;br /&gt;
[[Categories: MarkLogic]]&lt;/div&gt;</summary>
		<author><name>Bowersmt</name></author>
	</entry>
	<entry>
		<id>https://tech.churchofjesuschrist.org/wiki/index.php?title=What_is_MarkLogic%3F&amp;diff=70543</id>
		<title>What is MarkLogic?</title>
		<link rel="alternate" type="text/html" href="https://tech.churchofjesuschrist.org/wiki/index.php?title=What_is_MarkLogic%3F&amp;diff=70543"/>
		<updated>2014-11-14T02:06:32Z</updated>

		<summary type="html">&lt;p&gt;Bowersmt: Changed link name&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;br /&gt;
== What is MarkLogic? ==&lt;br /&gt;
[http://www.marklogic.com/what-is-marklogic/ MarkLogic] is a [http://www.marklogic.com/what-is-marklogic/inside-marklogic/ &#039;&#039;&#039;REST application server&#039;&#039;&#039;, &#039;&#039;&#039;document database&#039;&#039;&#039;, and &#039;&#039;&#039;search engine&#039;&#039;&#039;]. It is REST through and through. It is built specifically for hypertext documents, links, metadata, URIs, MIME types, and HTTP. It is schema-agnostic because it is automatically aware of the independent structure of each of its JSON and XML documents. It is search-centric because it can search for &#039;&#039;any combination&#039;&#039; of words, values, structures, and links within and across documents. It scales horizontally to hundreds of servers within and between data centers while maintaining ACID-compliant transactions. &lt;br /&gt;
&lt;br /&gt;
MarkLogic has the following [http://www.marklogic.com/what-is-marklogic/enterprise-nosql/ enterprise features]:&lt;br /&gt;
* [http://www.marklogic.com/resources/java-developers-guide/ Java APIs]&lt;br /&gt;
* [http://en.wikipedia.org/wiki/Node.js Node.js APIs]&lt;br /&gt;
* [http://developer.marklogic.com/learn/2009-07-search-api-walkthrough Search] and [http://developer.marklogic.com/learn/arch/search-and-indexing Query]&lt;br /&gt;
* [http://www.marklogic.com/blog/can-you-pass-the-acid-test/ ACID Transactions]&lt;br /&gt;
* [http://www.marklogic.com/resources/marklogic-high-availability-and-disaster-recovery/resource_download/datasheets/ High Availability] and [http://docs.marklogic.com/guide/database-replication/dbrep_intro#chapter Disaster Recovery]&lt;br /&gt;
* [http://www.marklogic.com/resources/marklogic-flexible-replication/resource_download/datasheets/ Replication within and across data centers]&lt;br /&gt;
* [http://docs.marklogic.com/guide/admin/security#chapter Government-grade Security]&lt;br /&gt;
* [https://docs.marklogic.com/guide/cluster.pdf Scalability] and [https://docs.marklogic.com/guide/admin/database-rebalancing#chapter Elasticity]&lt;br /&gt;
* [https://docs.marklogic.com/guide/ec2/managing#chapter On-premise or Cloud Deployment (especially AWS)]&lt;br /&gt;
* [http://www.marklogic.com/resources/marklogic-and-hadoop/resource_download/datasheets/ Hadoop for Storage and Compute]&lt;br /&gt;
* [http://www.marklogic.com/resources/marklogic-semantics-mlw14/ Semantics]&lt;br /&gt;
&lt;br /&gt;
== What is REST? ==&lt;br /&gt;
REST is an architectural style that uses a uniform resource identifier (&#039;&#039;&#039;URI&#039;&#039;&#039;) and a web protocol (&#039;&#039;&#039;HTTP/HTTPS&#039;&#039;&#039;) to request and transfer a representation (&#039;&#039;&#039;MIME media type&#039;&#039;&#039;) of the state of a resource (&#039;&#039;&#039;document&#039;&#039;&#039;) at a point in time from a server to a client. &lt;br /&gt;
&lt;br /&gt;
REST was coined and defined by Roy Fielding in his &lt;br /&gt;
[http://www.ics.uci.edu/~fielding/pubs/dissertation/top.htm dissertation, &#039;&#039;Architectural Styles and the Design of Network-based Software Architectures&#039;&#039;].  REST standardizes and documents the patterns used in the world wide web: self-documenting hypertext with data and metadata (HTML), stateless request/response communication protocol (HTTP/HTTPS), resource locators (URL), multiple representations per URL (MIME types), and downloading code on demand to process resources (JavaScript, CSS, etc.).&lt;br /&gt;
&lt;br /&gt;
REST consists of three main concepts: &lt;br /&gt;
* (RE) Representation&lt;br /&gt;
* (S)  State &lt;br /&gt;
* (T)  Transfer &lt;br /&gt;
&lt;br /&gt;
== Why is MarkLogic RESTful? ==&lt;br /&gt;
&lt;br /&gt;
=== &#039;&#039;&#039;Representation and MarkLogic&#039;&#039;&#039; === &lt;br /&gt;
* A representation is a document that represents a resource. It has three requirements: MIME media type, URI, and hypertext.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;MIME type:&#039;&#039;&#039; Each resource can be represented by one or more types of documents. The MIME media type defines the representation a client requests. A client may request the resource to be represented as JSON, XML, HTML, PNG, PDF, etc. &lt;br /&gt;
**&#039;&#039;&#039;MarkLogic&#039;&#039;&#039; stores any type of document and assigns the appropriate [http://developer.marklogic.com/blog/document-formats-part2 MIME type] to it. It can fully index, query, search, and process JSON, XML, and RDF documents. It meets the REST requirement of being able to transform JSON, XML, and RDF documents into any other MIME type. It knows how to execute JavaScript, XQuery, XSLT, and SPARQL documents. It knows how [http://docs.marklogic.com/guide/cpf/default#chapter to transform into XHTML] the content, formatting, and structure of Microsoft Word, PowerPoint, Excel, textual PDF, DocBook, and CSS  documents. (It can also use Microsoft Office to create, edit, and manage content in MarkLogic.) It knows how to [https://docs.marklogic.com/guide/search-dev/binary-document-metadata extract metadata and text from over 138 types of binary documents], such as raster images, vector images, videos, archive files, database files, encoded emails, presentations, spreadsheets, word-processing documents, text formats. &lt;br /&gt;
**Few NoSQL databases use MIME types to identify the media type of each document.  Most NoSQL databases support only one type of data and it is usually proprietary: columnar, BSON, binary, etc. Most cannot transform from one MIME type to another.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;URI:&#039;&#039;&#039; A resource is identified by a globally unique identifier (URI). &#039;&#039;&#039;MarkLogic&#039;&#039;&#039; identifies each document with a [http://developer.marklogic.com/try/rest/page2 unique URI]. A document in MarkLogic is like a row in a table in a schema in a relational database. A URI is liberating. It provides random access to any resource anywhere. It is like being able to retrieve any row in any table in any schema of a relational database without having to know what table and schema the row is stored in.  &lt;br /&gt;
**Navigating URL hierarchy is fundamental to REST. MarkLogic understands the hierarchy within a URI, which is represented by slashes &amp;quot;/&amp;quot;, such as https://www.lds.org/scriptures/ot/gen/1  MarkLogic treats the items between the slashes as folders. The URI of each document automatically places it in a folder in a folder hierarchy. A URI automatically defines the folder hierarchy.  In the example URI above, the document for Genesis chapter 1, is located in the Genesis folder, which is located in the Old Testament folder, which is located in the Scriptures folder on lds.org.  &#039;&#039;&#039;MarkLogic&#039;&#039;&#039; indexes the documents in each folder and its subfolders. This makes it fast and easy to retrieve any or all documents in any folder and/or its subfolders.&lt;br /&gt;
**Few NoSQL databases use the URI as the primary key for their documents or data. They also don&#039;t index the URI hierarchically to filter documents by folder and subfolder.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Hypertext:&#039;&#039;&#039; A document should contain data that represents the resource. The data should be &#039;&#039;&#039;human readable and self-documenting&#039;&#039;&#039;, like JSON, XML, RDF, and HTML. It should be &#039;&#039;&#039;linked data&#039;&#039;&#039; (i.e. the &amp;quot;hyper&amp;quot; in &amp;quot;hypertext&amp;quot;). A document should contain &#039;&#039;&#039; metadata links&#039;&#039;&#039; about the resource, such as RDF. It should contain &#039;&#039;&#039;action links&#039;&#039;&#039; to define what further actions can be done with the resource. It should contain &#039;&#039;&#039;related links&#039;&#039;&#039; to related resources, such as images, audio, video, related documents, etc. Each related link should define what actions can be done with the referenced resource, such as download it, display a link to it, execute a command against it, etc.)&lt;br /&gt;
**&#039;&#039;&#039;Hypertext&#039;&#039;&#039; or &#039;&#039;&#039;hypermedia&#039;&#039;&#039; documents must have all these features. Hyperlinks are what the &amp;quot;hyper&amp;quot; in hypertext and hypermedia refers to.  You can&#039;t have REST without &#039;&#039;metadata links&#039;&#039; to define what the data means, &#039;&#039;action links&#039;&#039; to know how to work with the resource, and &#039;&#039;related links&#039;&#039; to connect resources. It should all be human readable and self-documenting so a developer does not have to read documentation to know how to interact with a REST web service and its documents. &lt;br /&gt;
** &#039;&#039;&#039;MarkLogic&#039;&#039;&#039; meets all the requirements for hypertext representation. It is designed around MIME types, URIs, and Linked data.  It stores documents with their MIME types as [http://www.w3schools.com/json/ JSON], [http://www.w3schools.com/xml/ XML], [http://www.w3schools.com/webservices/ws_rdf_intro.asp RDF], [http://www.w3schools.com/html/ HTML], etc.  These documents are human-readable and self-documenting, which MarkLogic leverages to recognize and index each document&#039;s data, data structure, metadata links, action links, and related links. This makes it easy to &#039;&#039;&#039;search&#039;&#039;&#039;, &#039;&#039;&#039;query&#039;&#039;&#039;, &#039;&#039;&#039;transform&#039;&#039;&#039;, and &#039;&#039;&#039;deliver&#039;&#039;&#039; hypertext documents.  MarkLogic can also store any type of binary document and deliver it as a related resource, such as an image, video, or audio. MarkLogic is designed to process simple links and RDF links using [http://en.wikipedia.org/wiki/SPARQL SPARQL] and [https://docs.marklogic.com/xinc XInclude]. MarkLogic can represent links in many formats:  [https://docs.marklogic.com/xp XPointer], [https://docs.marklogic.com/guide/semantics/loading#id_97709 RDF/XML], [https://docs.marklogic.com/guide/semantics/loading#id_79194 RDF/JSON], [https://docs.marklogic.com/guide/semantics/loading#id_73211 Turtle], [https://docs.marklogic.com/guide/semantics/loading#id_70596 N-Triples], [https://docs.marklogic.com/guide/semantics/loading#id_61596 N-Quads], and [https://docs.marklogic.com/guide/semantics/loading#id_74485 TriG].&lt;br /&gt;
**No other NoSQL database natively indexes and fully processes all the document types required for REST hypertext: JSON, XML, RDF, HTML, CSS, and JavaScript.&lt;br /&gt;
&lt;br /&gt;
=== &#039;&#039;&#039;State and MarkLogic&#039;&#039;&#039; === &lt;br /&gt;
* State in REST exists on the client and in server documents. It does not exist in the communications protocol or in the server as cached session data. &lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Server:&#039;&#039;&#039; All information needed to process a request must be presented in the request and processed against documents in the database. State must only be in the request and in database documents: state cannot be anywhere else, such as in a session cache. The documents in the server define the state of the server. A REST server should explicitly create a state machine that defines the acceptable actions that can transacted against documents in specific contexts.&lt;br /&gt;
**A REST transaction occurs at a &#039;&#039;&#039;point in time&#039;&#039;&#039;. The state of the data in the request is unchanging, but the state of the documents and state machines in the database are often changing. Since request state and database state are both required to process the request and since shifting state creates unpredictable results, a REST transaction should run at a point in time with unchanging state. Only an ACID-compliant database can ensure consistent state because it isolates each transaction from every other transaction. The only time REST does not need an ACID-compliant database is when database documents do not change, database state machines do not change, or when clients can live with the resultant level of unreliable and unpredictable results.&lt;br /&gt;
**&#039;&#039;&#039;MarkLogic&#039;&#039;&#039; meets all the requirements for REST state.  Its web services are stateless: there is no session cache. It is ACID compliant. It ensures each transaction occurs at a point in time and is isolated from all other transactions. This ensures consistent processing during a transaction -- even across billions of documents. MarkLogic is an [http://en.wikipedia.org/wiki/Multiversion_concurrency_control MVCC] database which provides transaction isolation without slowing the performance of reads -- even when documents being read are being modified simultaneously by other transactions. (Also, like any other ACID database, when multiple updates and deletes compete for the same documents, they will impact each other&#039;s performance because change has to be serialized.)  &lt;br /&gt;
** Most other NoSQL databases are not ACID compliant. They are only suitable for REST services when their documents or data do not change or when the rate of change is slow enough or dispersed enough that it creates an acceptable level of unreliability and unpredictability.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Client:&#039;&#039;&#039; A REST client, such as a web browser or spider, locally maintains transactional state, such as what to do in response to documents and result codes that are returned from server transactions. An application exists only in the client -- not in the server (although, a server may deliver application code to a client, such as when a web server downloads HTML, CSS, and JavaScript to a browser). Client application code decides when to execute web service calls and it ties the results together to accomplish its purpose. This allows multiple authorized applications to reuse web services for a variety of purposes.  &lt;br /&gt;
**The server helps the client know what web service calls are available by providing action links with each response.  Action links are contextual and the context is based on the application account, user account, database documents, links within and between documents, the server state machine, etc. Through action links, the server can inform a client application what web service calls are permissible in any given context.&lt;br /&gt;
**&#039;&#039;&#039;MarkLogic&#039;&#039;&#039; meets the needs of client applications through its built-in ability to process and send action links to clients based on context. MarkLogic supports RDF triples and SPARQL, which enables context to be defined across applications, users, document state, links between documents, server state machine, etc. MarkLogic processes triples very quickly, which enables context to scale to billions of documents, millions of users, etc.&lt;br /&gt;
**&#039;&#039;&#039;MarkLogic&#039;&#039;&#039; also uses application and user permissions to filter which documents are returned to clients.  MarkLogic does this automatically and transparently by adding security filtering constraints into every search and query. This ensures no account can access unauthorized documents. This is fast because all security permissions are built-into MarkLogic&#039;s indexes -- which allows document-level security to scale across billions of documents.&lt;br /&gt;
** Most other NoSQL databases do not provide government-grade, document-level security and they also do not support RDF triples and SPARQL.&lt;br /&gt;
&lt;br /&gt;
Because MarkLogic can provide both the web service and database in one server, it is easy to use the state of the documents and the &lt;br /&gt;
&lt;br /&gt;
=== &#039;&#039;&#039;Transfer and MarkLogic&#039;&#039;&#039; === &lt;br /&gt;
* &#039;&#039;&#039;Transfer&#039;&#039;&#039; in REST is a communication protocol that enables a client to send a hypertext request to a server and receive back a hypertext response. The transfer must be stateless and be a request/response protocol. It must have human readable, self-descriptive headers.  The header must contain metadata about the request, such as the requested resource URI, MIME type of the resource, action to perform on the resource (such as get, put, post, patch, and delete). [http://www.w3schools.com/tags/ref_httpmethods.asp &#039;&#039;&#039;HTTP&#039;&#039;&#039;] (Hypertext transfer protocol) and &#039;&#039;&#039;HTTPS&#039;&#039;&#039; (secure HTTP) are designed specifically for REST (that is why they have &amp;quot;hypertext&amp;quot; in their name).&lt;br /&gt;
&lt;br /&gt;
* All &#039;&#039;&#039;MarkLogic&#039;&#039;&#039; communication is through through HTTP and HTTPS REST services (except for its SQL JDBC feature). This includes all internal cluster communication.  MarkLogic provides out-of-the-box REST interfaces for manipulating resources (insert, update, delete, query, search, transform, etc.) and administering MarkLogic (REST app servers, databases, indexes, clusters, etc).  MarkLogic makes it very easy to create custom REST services because everything in MarkLogic is built around REST and because they provide simple and powerful application server APIs.&lt;br /&gt;
&lt;br /&gt;
== MarkLogic Query and Search ==&lt;br /&gt;
MarkLogic is unlike relational databases (and a few NoSQL databases) where they use full table scans to retrieve every row in the table unless a query accesses less than 20% of the rows and then they use an index.  MarkLogic does not do full table scans.  It needs all queries to be resolved out of the indexes.  For that reason, it indexes most things and allows you to index more.&lt;br /&gt;
&lt;br /&gt;
MarkLogic can query and search -- and use both in combination.  MarkLogic uses indexes to execute searches and queries. The same indexes are used for both.  The difference between search and query is how documents are sorted.  Searches sort by relevance and queries sort by values. MarkLogic uses indexes to extract words, values, structures, and links out of documents. &lt;br /&gt;
&lt;br /&gt;
This enables you to search and query for documents as if they contained only&lt;br /&gt;
*&#039;&#039;&#039;Words:&#039;&#039;&#039; a flat set of words without structure, such as &amp;lt;br&amp;gt;&amp;lt;code&amp;gt;[&amp;quot;Mary&amp;quot; &amp;quot;had&amp;quot;, &amp;quot;a&amp;quot;, &amp;quot;little&amp;quot;, &amp;quot;lamb&amp;quot;]&amp;lt;/code&amp;gt;&lt;br /&gt;
*&#039;&#039;&#039;Phrases:&#039;&#039;&#039; a flat set of phrases without structure, such as &amp;lt;br&amp;gt;&amp;lt;code&amp;gt;[&amp;quot;Mary had&amp;quot;, &amp;quot;had a&amp;quot;, &amp;quot;a little&amp;quot;, &amp;quot;little lamb&amp;quot;]&amp;lt;/code&amp;gt;&lt;br /&gt;
*&#039;&#039;&#039;Elements:&#039;&#039;&#039; a flat set of elements without values, such as &amp;lt;br&amp;gt;&amp;lt;code&amp;gt;[&amp;quot;poem&amp;quot;, &amp;quot;text&amp;quot;, &amp;quot;line&amp;quot;]&amp;lt;/code&amp;gt;&lt;br /&gt;
*&#039;&#039;&#039;Element-values:&#039;&#039;&#039; a flat set of elements with string values, such as &amp;lt;br&amp;gt;&amp;lt;code&amp;gt;&amp;quot;line&amp;quot;: &amp;quot;Mary had a little lamb&amp;quot;&amp;lt;/code&amp;gt;&lt;br /&gt;
*&#039;&#039;&#039;Element-words:&#039;&#039;&#039; a flat set of elements with words, such as &amp;lt;br&amp;gt;&amp;lt;code&amp;gt;&amp;quot;line&amp;quot;: [&amp;quot;Mary&amp;quot; &amp;quot;had&amp;quot;, &amp;quot;a&amp;quot;, &amp;quot;little&amp;quot;, &amp;quot;lamb&amp;quot;]&amp;lt;/code&amp;gt;&lt;br /&gt;
*&#039;&#039;&#039;Element-phrases:&#039;&#039;&#039; a flat set of elements with phrases, such as &amp;lt;br&amp;gt;&amp;lt;code&amp;gt;&amp;quot;line&amp;quot;: [&amp;quot;Mary had&amp;quot;, &amp;quot;had a&amp;quot;, &amp;quot;a little&amp;quot;, &amp;quot;little lamb&amp;quot;]&amp;lt;/code&amp;gt;&lt;br /&gt;
*&#039;&#039;&#039;Element-value lexicon:&#039;&#039;&#039; a flat set of elements with typed values, such as &amp;lt;br&amp;gt;&amp;lt;code&amp;gt;&amp;quot;lineSequence&amp;quot;: 3&amp;lt;/code&amp;gt;&amp;lt;br&amp;gt; or a list, count, or co-occurrence of element values scoped to a database, set of documents, or one document.&lt;br /&gt;
*&#039;&#039;&#039;XPath-structure-value lexicon:&#039;&#039;&#039; a flat set of hierarchical elements with typed values, such as &amp;lt;br&amp;gt;&amp;lt;code&amp;gt;poem.text.line.lineSequence: 3&amp;lt;/code&amp;gt;&amp;lt;br&amp;gt; or a list, count, or co-occurrence of hierarchical element values scoped to a database, set of documents, or one document.&lt;br /&gt;
*&#039;&#039;&#039;XPath-structure:&#039;&#039;&#039;hierarchical structures without values, such as &amp;lt;br&amp;gt;&amp;lt;code&amp;gt;poem.text.line&amp;lt;/code&amp;gt;&lt;br /&gt;
*&#039;&#039;&#039;XPath-structure-words:&#039;&#039;&#039; hierarchical structures with words, such as &amp;lt;br&amp;gt;&amp;lt;code&amp;gt;poem.text.line: [&amp;quot;Mary&amp;quot;, &amp;quot;had&amp;quot;, &amp;quot;a&amp;quot;, &amp;quot;little&amp;quot;, &amp;quot;lamb&amp;quot;]&amp;lt;/code&amp;gt;&lt;br /&gt;
*&#039;&#039;&#039;XPath-structure-phrases:&#039;&#039;&#039; hierarchical structures with phrases, such as &amp;lt;br&amp;gt;&amp;lt;code&amp;gt;poem.text.line: [&amp;quot;Mary had&amp;quot;, &amp;quot;had a&amp;quot;, &amp;quot;a little&amp;quot;, &amp;quot;little lamb&amp;quot;]&amp;lt;/code&amp;gt;&lt;br /&gt;
*&#039;&#039;&#039;XPath-structure-values:&#039;&#039;&#039; hierarchical structures with values, such as &amp;lt;br&amp;gt;&amp;lt;code&amp;gt;poem.text.line: &amp;quot;Mary had a little lamb&amp;quot;&amp;lt;/code&amp;gt;&lt;br /&gt;
*&#039;&#039;&#039;RDF document links&#039;&#039;&#039; to other documents, such as &amp;lt;br&amp;gt;&amp;lt;code&amp;gt;{&amp;quot;subject&amp;quot;: &amp;quot;http://example.org/documents/thisDoc&amp;quot;, &amp;quot;predicate&amp;quot;: &amp;quot;http://example.org/predicates/relatesSomehowTo&amp;quot;, &amp;quot;object&amp;quot;: &amp;quot;http://example.org/documents/thatDoc&amp;quot;}&amp;lt;/code&amp;gt;&lt;br /&gt;
*&#039;&#039;&#039;RDF abstract links&#039;&#039;&#039; to other abstract concepts, such as &amp;lt;br&amp;gt;&amp;lt;code&amp;gt;{&amp;quot;subject&amp;quot;: &amp;quot;http://example.org/documents/thisDoc&amp;quot;, &amp;quot;predicate&amp;quot;: &amp;quot;http://example.org/predicates/relatesSomehowTo&amp;quot;, &amp;quot;object&amp;quot;: &amp;quot;http://example.org/documents/someConceptWithNoDocumentAtTheURI&amp;quot;}&amp;lt;/code&amp;gt;&lt;br /&gt;
*&#039;&#039;&#039;RDF data links&#039;&#039;&#039; to data, such as &amp;lt;br&amp;gt;&amp;lt;code&amp;gt;{&amp;quot;subject&amp;quot;: &amp;quot;http://example.org/documents/thisDoc&amp;quot;, &amp;quot;predicate&amp;quot;: &amp;quot;http://example.org/predicates/ageInYears&amp;quot;, &amp;quot;object&amp;quot;: 12}&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
MarkLogic can combine any of these indexes in any way to find matching documents.  It can sort the result by relevance or by value. &lt;br /&gt;
&lt;br /&gt;
The [[MarkLogic Query and Search]] page provides more detail about how MarkLogic&#039;s unique indexes work and how they work together.&lt;br /&gt;
&lt;br /&gt;
[[Categories: MarkLogic]]&lt;/div&gt;</summary>
		<author><name>Bowersmt</name></author>
	</entry>
	<entry>
		<id>https://tech.churchofjesuschrist.org/wiki/index.php?title=What_is_MarkLogic%3F&amp;diff=70542</id>
		<title>What is MarkLogic?</title>
		<link rel="alternate" type="text/html" href="https://tech.churchofjesuschrist.org/wiki/index.php?title=What_is_MarkLogic%3F&amp;diff=70542"/>
		<updated>2014-11-14T01:29:28Z</updated>

		<summary type="html">&lt;p&gt;Bowersmt: Creation&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;br /&gt;
== What is MarkLogic? ==&lt;br /&gt;
[http://www.marklogic.com/what-is-marklogic/ MarkLogic] is a [http://www.marklogic.com/what-is-marklogic/inside-marklogic/ &#039;&#039;&#039;REST application server&#039;&#039;&#039;, &#039;&#039;&#039;document database&#039;&#039;&#039;, and &#039;&#039;&#039;search engine&#039;&#039;&#039;]. It is REST through and through. It is built specifically for hypertext documents, links, metadata, URIs, MIME types, and HTTP. It is schema-agnostic because it is automatically aware of the independent structure of each of its JSON and XML documents. It is search-centric because it can search for &#039;&#039;any combination&#039;&#039; of words, values, structures, and links within and across documents. It scales horizontally to hundreds of servers within and between data centers while maintaining ACID-compliant transactions. &lt;br /&gt;
&lt;br /&gt;
MarkLogic has the following [http://www.marklogic.com/what-is-marklogic/enterprise-nosql/ enterprise features]:&lt;br /&gt;
* [http://www.marklogic.com/resources/java-developers-guide/ Java APIs]&lt;br /&gt;
* [http://en.wikipedia.org/wiki/Node.js Node.js APIs]&lt;br /&gt;
* [http://developer.marklogic.com/learn/2009-07-search-api-walkthrough Search] and [http://developer.marklogic.com/learn/arch/search-and-indexing Query]&lt;br /&gt;
* [http://www.marklogic.com/blog/can-you-pass-the-acid-test/ ACID Transactions]&lt;br /&gt;
* [http://www.marklogic.com/resources/marklogic-high-availability-and-disaster-recovery/resource_download/datasheets/ High Availability] and [http://docs.marklogic.com/guide/database-replication/dbrep_intro#chapter Disaster Recovery]&lt;br /&gt;
* [http://www.marklogic.com/resources/marklogic-flexible-replication/resource_download/datasheets/ Replication within and across data centers]&lt;br /&gt;
* [http://docs.marklogic.com/guide/admin/security#chapter Government-grade Security]&lt;br /&gt;
* [https://docs.marklogic.com/guide/cluster.pdf Scalability] and [https://docs.marklogic.com/guide/admin/database-rebalancing#chapter Elasticity]&lt;br /&gt;
* [https://docs.marklogic.com/guide/ec2/managing#chapter On-premise or Cloud Deployment (especially AWS)]&lt;br /&gt;
* [http://www.marklogic.com/resources/marklogic-and-hadoop/resource_download/datasheets/ Hadoop for Storage and Compute]&lt;br /&gt;
* [http://www.marklogic.com/resources/marklogic-semantics-mlw14/ Semantics]&lt;br /&gt;
&lt;br /&gt;
== What is REST? ==&lt;br /&gt;
REST is an architectural style that uses a uniform resource identifier (&#039;&#039;&#039;URI&#039;&#039;&#039;) and a web protocol (&#039;&#039;&#039;HTTP/HTTPS&#039;&#039;&#039;) to request and transfer a representation (&#039;&#039;&#039;MIME media type&#039;&#039;&#039;) of the state of a resource (&#039;&#039;&#039;document&#039;&#039;&#039;) at a point in time from a server to a client. &lt;br /&gt;
&lt;br /&gt;
REST was coined and defined by Roy Fielding in his &lt;br /&gt;
[http://www.ics.uci.edu/~fielding/pubs/dissertation/top.htm dissertation, &#039;&#039;Architectural Styles and the Design of Network-based Software Architectures&#039;&#039;].  REST standardizes and documents the patterns used in the world wide web: self-documenting hypertext with data and metadata (HTML), stateless request/response communication protocol (HTTP/HTTPS), resource locators (URL), multiple representations per URL (MIME types), and downloading code on demand to process resources (JavaScript, CSS, etc.).&lt;br /&gt;
&lt;br /&gt;
REST consists of three main concepts: &lt;br /&gt;
* (RE) Representation&lt;br /&gt;
* (S)  State &lt;br /&gt;
* (T)  Transfer &lt;br /&gt;
&lt;br /&gt;
== Why is MarkLogic RESTful? ==&lt;br /&gt;
&lt;br /&gt;
=== &#039;&#039;&#039;Representation and MarkLogic&#039;&#039;&#039; === &lt;br /&gt;
* A representation is a document that represents a resource. It has three requirements: MIME media type, URI, and hypertext.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;MIME type:&#039;&#039;&#039; Each resource can be represented by one or more types of documents. The MIME media type defines the representation a client requests. A client may request the resource to be represented as JSON, XML, HTML, PNG, PDF, etc. &lt;br /&gt;
**&#039;&#039;&#039;MarkLogic&#039;&#039;&#039; stores any type of document and assigns the appropriate [http://developer.marklogic.com/blog/document-formats-part2 MIME type] to it. It can fully index, query, search, and process JSON, XML, and RDF documents. It meets the REST requirement of being able to transform JSON, XML, and RDF documents into any other MIME type. It knows how to execute JavaScript, XQuery, XSLT, and SPARQL documents. It knows how [http://docs.marklogic.com/guide/cpf/default#chapter to transform into XHTML] the content, formatting, and structure of Microsoft Word, PowerPoint, Excel, textual PDF, DocBook, and CSS  documents. (It can also use Microsoft Office to create, edit, and manage content in MarkLogic.) It knows how to [https://docs.marklogic.com/guide/search-dev/binary-document-metadata extract metadata and text from over 138 types of binary documents], such as raster images, vector images, videos, archive files, database files, encoded emails, presentations, spreadsheets, word-processing documents, text formats. &lt;br /&gt;
**Few NoSQL databases use MIME types to identify the media type of each document.  Most NoSQL databases support only one type of data and it is usually proprietary: columnar, BSON, binary, etc. Most cannot transform from one MIME type to another.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;URI:&#039;&#039;&#039; A resource is identified by a globally unique identifier (URI). &#039;&#039;&#039;MarkLogic&#039;&#039;&#039; identifies each document with a [http://developer.marklogic.com/try/rest/page2 unique URI]. A document in MarkLogic is like a row in a table in a schema in a relational database. A URI is liberating. It provides random access to any resource anywhere. It is like being able to retrieve any row in any table in any schema of a relational database without having to know what table and schema the row is stored in.  &lt;br /&gt;
**Navigating URL hierarchy is fundamental to REST. MarkLogic understands the hierarchy within a URI, which is represented by slashes &amp;quot;/&amp;quot;, such as https://www.lds.org/scriptures/ot/gen/1  MarkLogic treats the items between the slashes as folders. The URI of each document automatically places it in a folder in a folder hierarchy. A URI automatically defines the folder hierarchy.  In the example URI above, the document for Genesis chapter 1, is located in the Genesis folder, which is located in the Old Testament folder, which is located in the Scriptures folder on lds.org.  &#039;&#039;&#039;MarkLogic&#039;&#039;&#039; indexes the documents in each folder and its subfolders. This makes it fast and easy to retrieve any or all documents in any folder and/or its subfolders.&lt;br /&gt;
**Few NoSQL databases use the URI as the primary key for their documents or data. They also don&#039;t index the URI hierarchically to filter documents by folder and subfolder.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Hypertext:&#039;&#039;&#039; A document should contain data that represents the resource. The data should be &#039;&#039;&#039;human readable and self-documenting&#039;&#039;&#039;, like JSON, XML, RDF, and HTML. It should be &#039;&#039;&#039;linked data&#039;&#039;&#039; (i.e. the &amp;quot;hyper&amp;quot; in &amp;quot;hypertext&amp;quot;). A document should contain &#039;&#039;&#039; metadata links&#039;&#039;&#039; about the resource, such as RDF. It should contain &#039;&#039;&#039;action links&#039;&#039;&#039; to define what further actions can be done with the resource. It should contain &#039;&#039;&#039;related links&#039;&#039;&#039; to related resources, such as images, audio, video, related documents, etc. Each related link should define what actions can be done with the referenced resource, such as download it, display a link to it, execute a command against it, etc.)&lt;br /&gt;
**&#039;&#039;&#039;Hypertext&#039;&#039;&#039; or &#039;&#039;&#039;hypermedia&#039;&#039;&#039; documents must have all these features. Hyperlinks are what the &amp;quot;hyper&amp;quot; in hypertext and hypermedia refers to.  You can&#039;t have REST without &#039;&#039;metadata links&#039;&#039; to define what the data means, &#039;&#039;action links&#039;&#039; to know how to work with the resource, and &#039;&#039;related links&#039;&#039; to connect resources. It should all be human readable and self-documenting so a developer does not have to read documentation to know how to interact with a REST web service and its documents. &lt;br /&gt;
** &#039;&#039;&#039;MarkLogic&#039;&#039;&#039; meets all the requirements for hypertext representation. It is designed around MIME types, URIs, and Linked data.  It stores documents with their MIME types as [http://www.w3schools.com/json/ JSON], [http://www.w3schools.com/xml/ XML], [http://www.w3schools.com/webservices/ws_rdf_intro.asp RDF], [http://www.w3schools.com/html/ HTML], etc.  These documents are human-readable and self-documenting, which MarkLogic leverages to recognize and index each document&#039;s data, data structure, metadata links, action links, and related links. This makes it easy to &#039;&#039;&#039;search&#039;&#039;&#039;, &#039;&#039;&#039;query&#039;&#039;&#039;, &#039;&#039;&#039;transform&#039;&#039;&#039;, and &#039;&#039;&#039;deliver&#039;&#039;&#039; hypertext documents.  MarkLogic can also store any type of binary document and deliver it as a related resource, such as an image, video, or audio. MarkLogic is designed to process simple links and RDF links using [http://en.wikipedia.org/wiki/SPARQL SPARQL] and [https://docs.marklogic.com/xinc XInclude]. MarkLogic can represent links in many formats:  [https://docs.marklogic.com/xp XPointer], [https://docs.marklogic.com/guide/semantics/loading#id_97709 RDF/XML], [https://docs.marklogic.com/guide/semantics/loading#id_79194 RDF/JSON], [https://docs.marklogic.com/guide/semantics/loading#id_73211 Turtle], [https://docs.marklogic.com/guide/semantics/loading#id_70596 N-Triples], [https://docs.marklogic.com/guide/semantics/loading#id_61596 N-Quads], and [https://docs.marklogic.com/guide/semantics/loading#id_74485 TriG].&lt;br /&gt;
**No other NoSQL database natively indexes and fully processes all the document types required for REST hypertext: JSON, XML, RDF, HTML, CSS, and JavaScript.&lt;br /&gt;
&lt;br /&gt;
=== &#039;&#039;&#039;State and MarkLogic&#039;&#039;&#039; === &lt;br /&gt;
* State in REST exists on the client and in server documents. It does not exist in the communications protocol or in the server as cached session data. &lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Server:&#039;&#039;&#039; All information needed to process a request must be presented in the request and processed against documents in the database. State must only be in the request and in database documents: state cannot be anywhere else, such as in a session cache. The documents in the server define the state of the server. A REST server should explicitly create a state machine that defines the acceptable actions that can transacted against documents in specific contexts.&lt;br /&gt;
**A REST transaction occurs at a &#039;&#039;&#039;point in time&#039;&#039;&#039;. The state of the data in the request is unchanging, but the state of the documents and state machines in the database are often changing. Since request state and database state are both required to process the request and since shifting state creates unpredictable results, a REST transaction should run at a point in time with unchanging state. Only an ACID-compliant database can ensure consistent state because it isolates each transaction from every other transaction. The only time REST does not need an ACID-compliant database is when database documents do not change, database state machines do not change, or when clients can live with the resultant level of unreliable and unpredictable results.&lt;br /&gt;
**&#039;&#039;&#039;MarkLogic&#039;&#039;&#039; meets all the requirements for REST state.  Its web services are stateless: there is no session cache. It is ACID compliant. It ensures each transaction occurs at a point in time and is isolated from all other transactions. This ensures consistent processing during a transaction -- even across billions of documents. MarkLogic is an [http://en.wikipedia.org/wiki/Multiversion_concurrency_control MVCC] database which provides transaction isolation without slowing the performance of reads -- even when documents being read are being modified simultaneously by other transactions. (Also, like any other ACID database, when multiple updates and deletes compete for the same documents, they will impact each other&#039;s performance because change has to be serialized.)  &lt;br /&gt;
** Most other NoSQL databases are not ACID compliant. They are only suitable for REST services when their documents or data do not change or when the rate of change is slow enough or dispersed enough that it creates an acceptable level of unreliability and unpredictability.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Client:&#039;&#039;&#039; A REST client, such as a web browser or spider, locally maintains transactional state, such as what to do in response to documents and result codes that are returned from server transactions. An application exists only in the client -- not in the server (although, a server may deliver application code to a client, such as when a web server downloads HTML, CSS, and JavaScript to a browser). Client application code decides when to execute web service calls and it ties the results together to accomplish its purpose. This allows multiple authorized applications to reuse web services for a variety of purposes.  &lt;br /&gt;
**The server helps the client know what web service calls are available by providing action links with each response.  Action links are contextual and the context is based on the application account, user account, database documents, links within and between documents, the server state machine, etc. Through action links, the server can inform a client application what web service calls are permissible in any given context.&lt;br /&gt;
**&#039;&#039;&#039;MarkLogic&#039;&#039;&#039; meets the needs of client applications through its built-in ability to process and send action links to clients based on context. MarkLogic supports RDF triples and SPARQL, which enables context to be defined across applications, users, document state, links between documents, server state machine, etc. MarkLogic processes triples very quickly, which enables context to scale to billions of documents, millions of users, etc.&lt;br /&gt;
**&#039;&#039;&#039;MarkLogic&#039;&#039;&#039; also uses application and user permissions to filter which documents are returned to clients.  MarkLogic does this automatically and transparently by adding security filtering constraints into every search and query. This ensures no account can access unauthorized documents. This is fast because all security permissions are built-into MarkLogic&#039;s indexes -- which allows document-level security to scale across billions of documents.&lt;br /&gt;
** Most other NoSQL databases do not provide government-grade, document-level security and they also do not support RDF triples and SPARQL.&lt;br /&gt;
&lt;br /&gt;
Because MarkLogic can provide both the web service and database in one server, it is easy to use the state of the documents and the &lt;br /&gt;
&lt;br /&gt;
=== &#039;&#039;&#039;Transfer and MarkLogic&#039;&#039;&#039; === &lt;br /&gt;
* &#039;&#039;&#039;Transfer&#039;&#039;&#039; in REST is a communication protocol that enables a client to send a hypertext request to a server and receive back a hypertext response. The transfer must be stateless and be a request/response protocol. It must have human readable, self-descriptive headers.  The header must contain metadata about the request, such as the requested resource URI, MIME type of the resource, action to perform on the resource (such as get, put, post, patch, and delete). [http://www.w3schools.com/tags/ref_httpmethods.asp &#039;&#039;&#039;HTTP&#039;&#039;&#039;] (Hypertext transfer protocol) and &#039;&#039;&#039;HTTPS&#039;&#039;&#039; (secure HTTP) are designed specifically for REST (that is why they have &amp;quot;hypertext&amp;quot; in their name).&lt;br /&gt;
&lt;br /&gt;
* All &#039;&#039;&#039;MarkLogic&#039;&#039;&#039; communication is through through HTTP and HTTPS REST services (except for its SQL JDBC feature). This includes all internal cluster communication.  MarkLogic provides out-of-the-box REST interfaces for manipulating resources (insert, update, delete, query, search, transform, etc.) and administering MarkLogic (REST app servers, databases, indexes, clusters, etc).  MarkLogic makes it very easy to create custom REST services because everything in MarkLogic is built around REST and because they provide simple and powerful application server APIs.&lt;br /&gt;
&lt;br /&gt;
== MarkLogic Query and Search ==&lt;br /&gt;
MarkLogic is unlike relational databases (and a few NoSQL databases) where they use full table scans to retrieve every row in the table unless a query accesses less than 20% of the rows and then they use an index.  MarkLogic does not do full table scans.  It needs all queries to be resolved out of the indexes.  For that reason, it indexes most things and allows you to index more.&lt;br /&gt;
&lt;br /&gt;
MarkLogic can query and search -- and use both in combination.  MarkLogic uses indexes to execute searches and queries. The same indexes are used for both.  The difference between search and query is how documents are sorted.  Searches sort by relevance and queries sort by values. MarkLogic uses indexes to extract words, values, structures, and links out of documents. &lt;br /&gt;
&lt;br /&gt;
This enables you to search and query for documents as if they contained only&lt;br /&gt;
*&#039;&#039;&#039;Words:&#039;&#039;&#039; a flat set of words without structure, such as &amp;lt;br&amp;gt;&amp;lt;code&amp;gt;[&amp;quot;Mary&amp;quot; &amp;quot;had&amp;quot;, &amp;quot;a&amp;quot;, &amp;quot;little&amp;quot;, &amp;quot;lamb&amp;quot;]&amp;lt;/code&amp;gt;&lt;br /&gt;
*&#039;&#039;&#039;Phrases:&#039;&#039;&#039; a flat set of phrases without structure, such as &amp;lt;br&amp;gt;&amp;lt;code&amp;gt;[&amp;quot;Mary had&amp;quot;, &amp;quot;had a&amp;quot;, &amp;quot;a little&amp;quot;, &amp;quot;little lamb&amp;quot;]&amp;lt;/code&amp;gt;&lt;br /&gt;
*&#039;&#039;&#039;Elements:&#039;&#039;&#039; a flat set of elements without values, such as &amp;lt;br&amp;gt;&amp;lt;code&amp;gt;[&amp;quot;poem&amp;quot;, &amp;quot;text&amp;quot;, &amp;quot;line&amp;quot;]&amp;lt;/code&amp;gt;&lt;br /&gt;
*&#039;&#039;&#039;Element-values:&#039;&#039;&#039; a flat set of elements with string values, such as &amp;lt;br&amp;gt;&amp;lt;code&amp;gt;&amp;quot;line&amp;quot;: &amp;quot;Mary had a little lamb&amp;quot;&amp;lt;/code&amp;gt;&lt;br /&gt;
*&#039;&#039;&#039;Element-words:&#039;&#039;&#039; a flat set of elements with words, such as &amp;lt;br&amp;gt;&amp;lt;code&amp;gt;&amp;quot;line&amp;quot;: [&amp;quot;Mary&amp;quot; &amp;quot;had&amp;quot;, &amp;quot;a&amp;quot;, &amp;quot;little&amp;quot;, &amp;quot;lamb&amp;quot;]&amp;lt;/code&amp;gt;&lt;br /&gt;
*&#039;&#039;&#039;Element-phrases:&#039;&#039;&#039; a flat set of elements with phrases, such as &amp;lt;br&amp;gt;&amp;lt;code&amp;gt;&amp;quot;line&amp;quot;: [&amp;quot;Mary had&amp;quot;, &amp;quot;had a&amp;quot;, &amp;quot;a little&amp;quot;, &amp;quot;little lamb&amp;quot;]&amp;lt;/code&amp;gt;&lt;br /&gt;
*&#039;&#039;&#039;Element-value lexicon:&#039;&#039;&#039; a flat set of elements with typed values, such as &amp;lt;br&amp;gt;&amp;lt;code&amp;gt;&amp;quot;lineSequence&amp;quot;: 3&amp;lt;/code&amp;gt;&amp;lt;br&amp;gt; or a list, count, or co-occurrence of element values scoped to a database, set of documents, or one document.&lt;br /&gt;
*&#039;&#039;&#039;XPath-structure-value lexicon:&#039;&#039;&#039; a flat set of hierarchical elements with typed values, such as &amp;lt;br&amp;gt;&amp;lt;code&amp;gt;poem.text.line.lineSequence: 3&amp;lt;/code&amp;gt;&amp;lt;br&amp;gt; or a list, count, or co-occurrence of hierarchical element values scoped to a database, set of documents, or one document.&lt;br /&gt;
*&#039;&#039;&#039;XPath-structure:&#039;&#039;&#039;hierarchical structures without values, such as &amp;lt;br&amp;gt;&amp;lt;code&amp;gt;poem.text.line&amp;lt;/code&amp;gt;&lt;br /&gt;
*&#039;&#039;&#039;XPath-structure-words:&#039;&#039;&#039; hierarchical structures with words, such as &amp;lt;br&amp;gt;&amp;lt;code&amp;gt;poem.text.line: [&amp;quot;Mary&amp;quot;, &amp;quot;had&amp;quot;, &amp;quot;a&amp;quot;, &amp;quot;little&amp;quot;, &amp;quot;lamb&amp;quot;]&amp;lt;/code&amp;gt;&lt;br /&gt;
*&#039;&#039;&#039;XPath-structure-phrases:&#039;&#039;&#039; hierarchical structures with phrases, such as &amp;lt;br&amp;gt;&amp;lt;code&amp;gt;poem.text.line: [&amp;quot;Mary had&amp;quot;, &amp;quot;had a&amp;quot;, &amp;quot;a little&amp;quot;, &amp;quot;little lamb&amp;quot;]&amp;lt;/code&amp;gt;&lt;br /&gt;
*&#039;&#039;&#039;XPath-structure-values:&#039;&#039;&#039; hierarchical structures with values, such as &amp;lt;br&amp;gt;&amp;lt;code&amp;gt;poem.text.line: &amp;quot;Mary had a little lamb&amp;quot;&amp;lt;/code&amp;gt;&lt;br /&gt;
*&#039;&#039;&#039;RDF document links&#039;&#039;&#039; to other documents, such as &amp;lt;br&amp;gt;&amp;lt;code&amp;gt;{&amp;quot;subject&amp;quot;: &amp;quot;http://example.org/documents/thisDoc&amp;quot;, &amp;quot;predicate&amp;quot;: &amp;quot;http://example.org/predicates/relatesSomehowTo&amp;quot;, &amp;quot;object&amp;quot;: &amp;quot;http://example.org/documents/thatDoc&amp;quot;}&amp;lt;/code&amp;gt;&lt;br /&gt;
*&#039;&#039;&#039;RDF abstract links&#039;&#039;&#039; to other abstract concepts, such as &amp;lt;br&amp;gt;&amp;lt;code&amp;gt;{&amp;quot;subject&amp;quot;: &amp;quot;http://example.org/documents/thisDoc&amp;quot;, &amp;quot;predicate&amp;quot;: &amp;quot;http://example.org/predicates/relatesSomehowTo&amp;quot;, &amp;quot;object&amp;quot;: &amp;quot;http://example.org/documents/someConceptWithNoDocumentAtTheURI&amp;quot;}&amp;lt;/code&amp;gt;&lt;br /&gt;
*&#039;&#039;&#039;RDF data links&#039;&#039;&#039; to data, such as &amp;lt;br&amp;gt;&amp;lt;code&amp;gt;{&amp;quot;subject&amp;quot;: &amp;quot;http://example.org/documents/thisDoc&amp;quot;, &amp;quot;predicate&amp;quot;: &amp;quot;http://example.org/predicates/ageInYears&amp;quot;, &amp;quot;object&amp;quot;: 12}&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
MarkLogic can combine any of these indexes in any way to find matching documents.  It can sort the result by relevance or by value. &lt;br /&gt;
&lt;br /&gt;
The [[MarkLogic Search]] page provides more detail about how MarkLogic&#039;s unique indexes work and how they work together.&lt;br /&gt;
&lt;br /&gt;
[[Categories: MarkLogic]]&lt;/div&gt;</summary>
		<author><name>Bowersmt</name></author>
	</entry>
	<entry>
		<id>https://tech.churchofjesuschrist.org/wiki/index.php?title=MarkLogic&amp;diff=70541</id>
		<title>MarkLogic</title>
		<link rel="alternate" type="text/html" href="https://tech.churchofjesuschrist.org/wiki/index.php?title=MarkLogic&amp;diff=70541"/>
		<updated>2014-11-14T00:02:40Z</updated>

		<summary type="html">&lt;p&gt;Bowersmt: Turn this page into a landing page.&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== MarkLogic ==&lt;br /&gt;
This is the landing page for MarkLogic.  MarkLogic is an all-in-one application server, document database, and search engine.  It is entirely based on REST. For an extensive explanation of what MarkLogic is and what it can do, see [[What is MarkLogic?]]&lt;br /&gt;
&lt;br /&gt;
== Links to other MarkLogic Documents ==&lt;br /&gt;
* [[What is MarkLogic?]]&lt;br /&gt;
* [[Installing MarkLogic]]&lt;br /&gt;
* [[MarkLogic Training Resources]]&lt;br /&gt;
&lt;br /&gt;
[[Category:MarkLogic]]&lt;/div&gt;</summary>
		<author><name>Bowersmt</name></author>
	</entry>
	<entry>
		<id>https://tech.churchofjesuschrist.org/wiki/index.php?title=Category:MarkLogic&amp;diff=70539</id>
		<title>Category:MarkLogic</title>
		<link rel="alternate" type="text/html" href="https://tech.churchofjesuschrist.org/wiki/index.php?title=Category:MarkLogic&amp;diff=70539"/>
		<updated>2014-11-13T17:45:54Z</updated>

		<summary type="html">&lt;p&gt;Bowersmt: Created&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[[MarkLogic]] is the main landing page for MarkLogic.&lt;/div&gt;</summary>
		<author><name>Bowersmt</name></author>
	</entry>
	<entry>
		<id>https://tech.churchofjesuschrist.org/wiki/index.php?title=MarkLogic_Training_Resources&amp;diff=70538</id>
		<title>MarkLogic Training Resources</title>
		<link rel="alternate" type="text/html" href="https://tech.churchofjesuschrist.org/wiki/index.php?title=MarkLogic_Training_Resources&amp;diff=70538"/>
		<updated>2014-11-13T17:44:37Z</updated>

		<summary type="html">&lt;p&gt;Bowersmt: Changed category&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== MarkLogic Training Resources ==&lt;br /&gt;
* [http://developer.marklogic.com/blog/grokking-the-cts-api &amp;quot;Grokking the cts API&amp;quot;] is a great overview of MarkLogic&#039;s search and query capabilities, which are its most important feature.  Everything you do in MarkLogic should be focused around how MarkLogic indexes, searches, and queries documents.&lt;br /&gt;
&lt;br /&gt;
* [http://developer.marklogic.com/try/ninja/index Try Marklogic] is the best way to play with MarkLogic&#039;s search and query features.  Without installing anything, you can run queries and searches against an existing database in the cloud.&lt;br /&gt;
&lt;br /&gt;
* [http://developer.marklogic.com/learn MarkLogic Tutorials] guide you step-by-step through each major MarkLogic feature.  Some tutorials are short and sweet five minutes, and others take up to an hour or so.&lt;br /&gt;
&lt;br /&gt;
* [https://mlu.marklogic.com/registration/ Live Training] is available from MarkLogic at no cost.  A live instructor will work with you to show you how to build MarkLogic applications, administer MarkLogic, use Semantics (triples), and MarkLogic fundamentals (like search and queries).&lt;br /&gt;
&lt;br /&gt;
[[Category:MarkLogic]]&lt;/div&gt;</summary>
		<author><name>Bowersmt</name></author>
	</entry>
	<entry>
		<id>https://tech.churchofjesuschrist.org/wiki/index.php?title=MarkLogic_Training_Resources&amp;diff=70537</id>
		<title>MarkLogic Training Resources</title>
		<link rel="alternate" type="text/html" href="https://tech.churchofjesuschrist.org/wiki/index.php?title=MarkLogic_Training_Resources&amp;diff=70537"/>
		<updated>2014-11-13T17:43:46Z</updated>

		<summary type="html">&lt;p&gt;Bowersmt: Created MarkLogic Training Resources&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== MarkLogic Training Resources ==&lt;br /&gt;
* [http://developer.marklogic.com/blog/grokking-the-cts-api &amp;quot;Grokking the cts API&amp;quot;] is a great overview of MarkLogic&#039;s search and query capabilities, which are its most important feature.  Everything you do in MarkLogic should be focused around how MarkLogic indexes, searches, and queries documents.&lt;br /&gt;
&lt;br /&gt;
* [http://developer.marklogic.com/try/ninja/index Try Marklogic] is the best way to play with MarkLogic&#039;s search and query features.  Without installing anything, you can run queries and searches against an existing database in the cloud.&lt;br /&gt;
&lt;br /&gt;
* [http://developer.marklogic.com/learn MarkLogic Tutorials] guide you step-by-step through each major MarkLogic feature.  Some tutorials are short and sweet five minutes, and others take up to an hour or so.&lt;br /&gt;
&lt;br /&gt;
* [https://mlu.marklogic.com/registration/ Live Training] is available from MarkLogic at no cost.  A live instructor will work with you to show you how to build MarkLogic applications, administer MarkLogic, use Semantics (triples), and MarkLogic fundamentals (like search and queries).&lt;br /&gt;
&lt;br /&gt;
[[Category:MarkLogic Training]]&lt;/div&gt;</summary>
		<author><name>Bowersmt</name></author>
	</entry>
	<entry>
		<id>https://tech.churchofjesuschrist.org/wiki/index.php?title=MarkLogic&amp;diff=70536</id>
		<title>MarkLogic</title>
		<link rel="alternate" type="text/html" href="https://tech.churchofjesuschrist.org/wiki/index.php?title=MarkLogic&amp;diff=70536"/>
		<updated>2014-11-13T17:42:47Z</updated>

		<summary type="html">&lt;p&gt;Bowersmt: Turned this page into the main landing page for MarkLogic&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== What is MarkLogic? ==&lt;br /&gt;
&lt;br /&gt;
== Links to other MarkLogic Documents ==&lt;br /&gt;
[[Installing MarkLogic]]&lt;br /&gt;
[[MarkLogic Training Resources]]&lt;br /&gt;
&lt;br /&gt;
[[Category:MarkLogic]]&lt;/div&gt;</summary>
		<author><name>Bowersmt</name></author>
	</entry>
	<entry>
		<id>https://tech.churchofjesuschrist.org/wiki/index.php?title=Installing_MarkLogic&amp;diff=70535</id>
		<title>Installing MarkLogic</title>
		<link rel="alternate" type="text/html" href="https://tech.churchofjesuschrist.org/wiki/index.php?title=Installing_MarkLogic&amp;diff=70535"/>
		<updated>2014-11-13T17:38:19Z</updated>

		<summary type="html">&lt;p&gt;Bowersmt: Created new Installing MarkLogic page&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;br /&gt;
== Installing MarkLogic on Windows ==&lt;br /&gt;
&lt;br /&gt;
(These instructions are for Windows XP, Vista, and 7. Installation and server start-up may differ slightly for other operating systems.)&lt;br /&gt;
&lt;br /&gt;
# [http://developer.marklogic.com/products Download] the latest version of the MarkLogic Server for your operating system.&lt;br /&gt;
#* Upon clicking on the download link, you will need to agree to MarkLogic&#039;s Terms of Use.&lt;br /&gt;
# Execute the MarkLogic Server installer.&lt;br /&gt;
#* Choose a &amp;quot;Typical&amp;quot; setup. This will take about 5 minutes.&lt;br /&gt;
# After installation is complete start the Mark Logic Server.&lt;br /&gt;
#* (Windows Only) Go to Start &amp;gt; All Programs &amp;gt; MarkLogic Server &amp;gt; Start MarkLogic Server&lt;br /&gt;
#** Important! Right-click on &amp;quot;Start MarkLogic Server&amp;quot; and select &amp;quot;Run as administrator&amp;quot;. Otherwise, the server may not start.&lt;br /&gt;
#** If you get the error message &amp;quot;The application failed to initialize properly...&amp;quot;, then see [http://developer.marklogic.com/products/marklogic-server/requirements MarkLogic Server 4.x System Requirements] to download and install the necessary dll for your operating system. Then try starting the server again.&lt;br /&gt;
#** If start-up succeeds, you will not see any message.&lt;br /&gt;
# Go to the Mark Logic administration console:&lt;br /&gt;
#* (Windows Only) Go to Start &amp;gt; All Program &amp;gt; MarkLogic Server &amp;gt; Admin MarkLogic Server.&lt;br /&gt;
#* A browser window will open and you will be prompted to enter a license key.&lt;br /&gt;
#** If you do not yet have a license, do one of the following:&lt;br /&gt;
#*** (Employees Only) Request a license key by emailing [mailto:DL-ICS-MARKLOGIC DL-ICS-MARKLOGIC].&lt;br /&gt;
#**** Enter the licensee and the license key, then click &amp;quot;OK&amp;quot;. The MarkLogic Server will restart.&lt;br /&gt;
#*** (Non-employees Only) You may request a free license for community development by clicking the &amp;quot;Free&amp;quot; button and then entering the required information in the supplied form.&lt;br /&gt;
#**** &#039;&#039;&#039;Licensee&#039;&#039;&#039;. This is &#039;&#039;&#039;your&#039;&#039;&#039; name.&lt;br /&gt;
#**** &#039;&#039;&#039;Company&#039;&#039;&#039;. &#039;&#039;Do NOT put the name of the Church or any of its business entities in this field.&#039;&#039; You may put &amp;quot;Home&amp;quot; or &amp;quot;Community&amp;quot; in this field if you will be using the MarkLogic Server for personal or community development.&lt;br /&gt;
#**** &#039;&#039;&#039;Email&#039;&#039;&#039;. This is your personal email address.&lt;br /&gt;
#**** Choose &amp;quot;Select Community License&amp;quot;.&lt;br /&gt;
#**** Make a copy of your license information and then click &amp;quot;OK&amp;quot;. The MarkLogic Server will restart.&lt;br /&gt;
#* Accept the license agreement by scrolling to the bottom of the page and clicking &amp;quot;Accept&amp;quot;. The MarkLogic Server will restart.&lt;br /&gt;
#* You will now be prompted to install the initial databases and application servers. Click &amp;quot;OK&amp;quot; to continue. When installation is complete. The server will restart.&lt;br /&gt;
#* When prompted to enter an Admin username and password, enter &amp;quot;admin&amp;quot; as the user and &amp;quot;admin&amp;quot; as the password. Confirm the password and click &amp;quot;OK&amp;quot; to continue.&lt;br /&gt;
#* When prompted, enter the user name and password you supplied. You will then be redirected to the MarkLogic Server administration console.&lt;br /&gt;
# Configure an XDBC server&lt;br /&gt;
#* Expand &amp;quot;Groups&amp;quot;, then expand &amp;quot;Default&amp;quot;, and then select &amp;quot;App Servers&amp;quot;.&lt;br /&gt;
#*; &amp;lt;br/&amp;gt;[[File:marklogic-admin-step1.png]]&amp;lt;br/&amp;gt;&amp;lt;br/&amp;gt;&lt;br /&gt;
#* Click the tab &amp;quot;Create XDBC&amp;quot;&lt;br /&gt;
#** Supply an XDBC server name.&lt;br /&gt;
#*** For the Stack Petstore project, enter &amp;quot;stack-petstore&amp;quot;.&lt;br /&gt;
#** Supply a value for the module directory root.&lt;br /&gt;
#*** For the Stack Petstore project, enter &amp;quot;/&amp;quot;.&lt;br /&gt;
#** Supply a value for the port the XDBC server will listen to for connections.&lt;br /&gt;
#*** For the Stack Petstore project, enter &amp;quot;8010&amp;quot;.&lt;br /&gt;
#** For the modules field, choose &amp;quot;Modules&amp;quot; from the list of options.&lt;br /&gt;
#** Leave all other fields as they are, and click &amp;quot;OK&amp;quot; at the top of the page.&lt;br /&gt;
#*; &amp;lt;br/&amp;gt;[[File:marklogic-admin-step2.png]]&amp;lt;br/&amp;gt;&amp;lt;br/&amp;gt;&lt;br /&gt;
# To try out your Mark Logic installation, go to [http://localhost:8000 &amp;lt;nowiki&amp;gt;http://localhost:8000&amp;lt;/nowiki&amp;gt;] and login with your admin username.&lt;/div&gt;</summary>
		<author><name>Bowersmt</name></author>
	</entry>
	<entry>
		<id>https://tech.churchofjesuschrist.org/wiki/index.php?title=MarkLogic&amp;diff=70534</id>
		<title>MarkLogic</title>
		<link rel="alternate" type="text/html" href="https://tech.churchofjesuschrist.org/wiki/index.php?title=MarkLogic&amp;diff=70534"/>
		<updated>2014-11-13T17:37:05Z</updated>

		<summary type="html">&lt;p&gt;Bowersmt: Moving Installing MarkLogic to its own page&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== MarkLogic Training ==&lt;br /&gt;
* [http://developer.marklogic.com/blog/grokking-the-cts-api &amp;quot;Grokking the cts API&amp;quot;] is a great overview of MarkLogic&#039;s search and query capabilities, which are its most important feature.  Everything you do in MarkLogic should be focused around how MarkLogic indexes, searches, and queries documents.&lt;br /&gt;
&lt;br /&gt;
* [http://developer.marklogic.com/try/ninja/index Try Marklogic] is the best way to play with MarkLogic&#039;s search and query features.  Without installing anything, you can run queries and searches against an existing database in the cloud.&lt;br /&gt;
&lt;br /&gt;
* [http://developer.marklogic.com/learn MarkLogic Tutorials] guide you step-by-step through each major MarkLogic feature.  Some tutorials are short and sweet five minutes, and others take up to an hour or so.&lt;br /&gt;
&lt;br /&gt;
* [https://mlu.marklogic.com/registration/ Live Training] is available from MarkLogic at no cost.  A live instructor will work with you to show you how to build MarkLogic applications, administer MarkLogic, use Semantics (triples), and MarkLogic fundamentals (like search and queries).&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[Installing MarkLogic]]&lt;br /&gt;
&lt;br /&gt;
== Installing MarkLogic ==&lt;br /&gt;
&lt;br /&gt;
(These instructions are for Windows XP, Vista, and 7. Installation and server start-up may differ slightly for other operating systems.)&lt;br /&gt;
&lt;br /&gt;
# [http://developer.marklogic.com/products Download] the latest version of the MarkLogic Server for your operating system.&lt;br /&gt;
#* Upon clicking on the download link, you will need to agree to MarkLogic&#039;s Terms of Use.&lt;br /&gt;
# Execute the MarkLogic Server installer.&lt;br /&gt;
#* Choose a &amp;quot;Typical&amp;quot; setup. This will take about 5 minutes.&lt;br /&gt;
# After installation is complete start the Mark Logic Server.&lt;br /&gt;
#* (Windows Only) Go to Start &amp;gt; All Programs &amp;gt; MarkLogic Server &amp;gt; Start MarkLogic Server&lt;br /&gt;
#** Important! Right-click on &amp;quot;Start MarkLogic Server&amp;quot; and select &amp;quot;Run as administrator&amp;quot;. Otherwise, the server may not start.&lt;br /&gt;
#** If you get the error message &amp;quot;The application failed to initialize properly...&amp;quot;, then see [http://developer.marklogic.com/products/marklogic-server/requirements MarkLogic Server 4.x System Requirements] to download and install the necessary dll for your operating system. Then try starting the server again.&lt;br /&gt;
#** If start-up succeeds, you will not see any message.&lt;br /&gt;
# Go to the Mark Logic administration console:&lt;br /&gt;
#* (Windows Only) Go to Start &amp;gt; All Program &amp;gt; MarkLogic Server &amp;gt; Admin MarkLogic Server.&lt;br /&gt;
#* A browser window will open and you will be prompted to enter a license key.&lt;br /&gt;
#** If you do not yet have a license, do one of the following:&lt;br /&gt;
#*** (Employees Only) Request a license key by emailing [mailto:DL-ICS-MARKLOGIC DL-ICS-MARKLOGIC].&lt;br /&gt;
#**** Enter the licensee and the license key, then click &amp;quot;OK&amp;quot;. The MarkLogic Server will restart.&lt;br /&gt;
#*** (Non-employees Only) You may request a free license for community development by clicking the &amp;quot;Free&amp;quot; button and then entering the required information in the supplied form.&lt;br /&gt;
#**** &#039;&#039;&#039;Licensee&#039;&#039;&#039;. This is &#039;&#039;&#039;your&#039;&#039;&#039; name.&lt;br /&gt;
#**** &#039;&#039;&#039;Company&#039;&#039;&#039;. &#039;&#039;Do NOT put the name of the Church or any of its business entities in this field.&#039;&#039; You may put &amp;quot;Home&amp;quot; or &amp;quot;Community&amp;quot; in this field if you will be using the MarkLogic Server for personal or community development.&lt;br /&gt;
#**** &#039;&#039;&#039;Email&#039;&#039;&#039;. This is your personal email address.&lt;br /&gt;
#**** Choose &amp;quot;Select Community License&amp;quot;.&lt;br /&gt;
#**** Make a copy of your license information and then click &amp;quot;OK&amp;quot;. The MarkLogic Server will restart.&lt;br /&gt;
#* Accept the license agreement by scrolling to the bottom of the page and clicking &amp;quot;Accept&amp;quot;. The MarkLogic Server will restart.&lt;br /&gt;
#* You will now be prompted to install the initial databases and application servers. Click &amp;quot;OK&amp;quot; to continue. When installation is complete. The server will restart.&lt;br /&gt;
#* When prompted to enter an Admin username and password, enter &amp;quot;admin&amp;quot; as the user and &amp;quot;admin&amp;quot; as the password. Confirm the password and click &amp;quot;OK&amp;quot; to continue.&lt;br /&gt;
#* When prompted, enter the user name and password you supplied. You will then be redirected to the MarkLogic Server administration console.&lt;br /&gt;
# Configure an XDBC server&lt;br /&gt;
#* Expand &amp;quot;Groups&amp;quot;, then expand &amp;quot;Default&amp;quot;, and then select &amp;quot;App Servers&amp;quot;.&lt;br /&gt;
#*; &amp;lt;br/&amp;gt;[[File:marklogic-admin-step1.png]]&amp;lt;br/&amp;gt;&amp;lt;br/&amp;gt;&lt;br /&gt;
#* Click the tab &amp;quot;Create XDBC&amp;quot;&lt;br /&gt;
#** Supply an XDBC server name.&lt;br /&gt;
#*** For the Stack Petstore project, enter &amp;quot;stack-petstore&amp;quot;.&lt;br /&gt;
#** Supply a value for the module directory root.&lt;br /&gt;
#*** For the Stack Petstore project, enter &amp;quot;/&amp;quot;.&lt;br /&gt;
#** Supply a value for the port the XDBC server will listen to for connections.&lt;br /&gt;
#*** For the Stack Petstore project, enter &amp;quot;8010&amp;quot;.&lt;br /&gt;
#** For the modules field, choose &amp;quot;Modules&amp;quot; from the list of options.&lt;br /&gt;
#** Leave all other fields as they are, and click &amp;quot;OK&amp;quot; at the top of the page.&lt;br /&gt;
#*; &amp;lt;br/&amp;gt;[[File:marklogic-admin-step2.png]]&amp;lt;br/&amp;gt;&amp;lt;br/&amp;gt;&lt;br /&gt;
# To try out your Mark Logic installation, go to [http://localhost:8000 &amp;lt;nowiki&amp;gt;http://localhost:8000&amp;lt;/nowiki&amp;gt;] and login with your admin username.&lt;br /&gt;
&lt;br /&gt;
[[Category:LDS Java Stack]]&lt;/div&gt;</summary>
		<author><name>Bowersmt</name></author>
	</entry>
	<entry>
		<id>https://tech.churchofjesuschrist.org/wiki/index.php?title=MarkLogic&amp;diff=70533</id>
		<title>MarkLogic</title>
		<link rel="alternate" type="text/html" href="https://tech.churchofjesuschrist.org/wiki/index.php?title=MarkLogic&amp;diff=70533"/>
		<updated>2014-11-13T17:33:37Z</updated>

		<summary type="html">&lt;p&gt;Bowersmt: Added MarkLogic training information&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{Under construction|This page is a work in progress.}}&lt;br /&gt;
&lt;br /&gt;
== MarkLogic Training ==&lt;br /&gt;
* [http://developer.marklogic.com/blog/grokking-the-cts-api &amp;quot;Grokking the cts API&amp;quot;] is a great overview of MarkLogic&#039;s search and query capabilities, which are its most important feature.  Everything you do in MarkLogic should be focused around how MarkLogic indexes, searches, and queries documents.&lt;br /&gt;
&lt;br /&gt;
* [http://developer.marklogic.com/try/ninja/index Try Marklogic] is the best way to play with MarkLogic&#039;s search and query features.  Without installing anything, you can run queries and searches against an existing database in the cloud.&lt;br /&gt;
&lt;br /&gt;
* [http://developer.marklogic.com/learn MarkLogic Tutorials] guide you step-by-step through each major MarkLogic feature.  Some tutorials are short and sweet five minutes, and others take up to an hour or so.&lt;br /&gt;
&lt;br /&gt;
* [https://mlu.marklogic.com/registration/ Live Training] is available from MarkLogic at no cost.  A live instructor will work with you to show you how to build MarkLogic applications, administer MarkLogic, use Semantics (triples), and MarkLogic fundamentals (like search and queries).&lt;br /&gt;
&lt;br /&gt;
== Installing MarkLogic ==&lt;br /&gt;
&lt;br /&gt;
(These instructions are for Windows XP, Vista, and 7. Installation and server start-up may differ slightly for other operating systems.)&lt;br /&gt;
&lt;br /&gt;
# [http://developer.marklogic.com/products Download] the latest version of the MarkLogic Server for your operating system.&lt;br /&gt;
#* Upon clicking on the download link, you will need to agree to MarkLogic&#039;s Terms of Use.&lt;br /&gt;
# Execute the MarkLogic Server installer.&lt;br /&gt;
#* Choose a &amp;quot;Typical&amp;quot; setup. This will take about 5 minutes.&lt;br /&gt;
# After installation is complete start the Mark Logic Server.&lt;br /&gt;
#* (Windows Only) Go to Start &amp;gt; All Programs &amp;gt; MarkLogic Server &amp;gt; Start MarkLogic Server&lt;br /&gt;
#** Important! Right-click on &amp;quot;Start MarkLogic Server&amp;quot; and select &amp;quot;Run as administrator&amp;quot;. Otherwise, the server may not start.&lt;br /&gt;
#** If you get the error message &amp;quot;The application failed to initialize properly...&amp;quot;, then see [http://developer.marklogic.com/products/marklogic-server/requirements MarkLogic Server 4.x System Requirements] to download and install the necessary dll for your operating system. Then try starting the server again.&lt;br /&gt;
#** If start-up succeeds, you will not see any message.&lt;br /&gt;
# Go to the Mark Logic administration console:&lt;br /&gt;
#* (Windows Only) Go to Start &amp;gt; All Program &amp;gt; MarkLogic Server &amp;gt; Admin MarkLogic Server.&lt;br /&gt;
#* A browser window will open and you will be prompted to enter a license key.&lt;br /&gt;
#** If you do not yet have a license, do one of the following:&lt;br /&gt;
#*** (Employees Only) Request a license key by emailing [mailto:DL-ICS-MARKLOGIC DL-ICS-MARKLOGIC].&lt;br /&gt;
#**** Enter the licensee and the license key, then click &amp;quot;OK&amp;quot;. The MarkLogic Server will restart.&lt;br /&gt;
#*** (Non-employees Only) You may request a free license for community development by clicking the &amp;quot;Free&amp;quot; button and then entering the required information in the supplied form.&lt;br /&gt;
#**** &#039;&#039;&#039;Licensee&#039;&#039;&#039;. This is &#039;&#039;&#039;your&#039;&#039;&#039; name.&lt;br /&gt;
#**** &#039;&#039;&#039;Company&#039;&#039;&#039;. &#039;&#039;Do NOT put the name of the Church or any of its business entities in this field.&#039;&#039; You may put &amp;quot;Home&amp;quot; or &amp;quot;Community&amp;quot; in this field if you will be using the MarkLogic Server for personal or community development.&lt;br /&gt;
#**** &#039;&#039;&#039;Email&#039;&#039;&#039;. This is your personal email address.&lt;br /&gt;
#**** Choose &amp;quot;Select Community License&amp;quot;.&lt;br /&gt;
#**** Make a copy of your license information and then click &amp;quot;OK&amp;quot;. The MarkLogic Server will restart.&lt;br /&gt;
#* Accept the license agreement by scrolling to the bottom of the page and clicking &amp;quot;Accept&amp;quot;. The MarkLogic Server will restart.&lt;br /&gt;
#* You will now be prompted to install the initial databases and application servers. Click &amp;quot;OK&amp;quot; to continue. When installation is complete. The server will restart.&lt;br /&gt;
#* When prompted to enter an Admin username and password, enter &amp;quot;admin&amp;quot; as the user and &amp;quot;admin&amp;quot; as the password. Confirm the password and click &amp;quot;OK&amp;quot; to continue.&lt;br /&gt;
#* When prompted, enter the user name and password you supplied. You will then be redirected to the MarkLogic Server administration console.&lt;br /&gt;
# Configure an XDBC server&lt;br /&gt;
#* Expand &amp;quot;Groups&amp;quot;, then expand &amp;quot;Default&amp;quot;, and then select &amp;quot;App Servers&amp;quot;.&lt;br /&gt;
#*; &amp;lt;br/&amp;gt;[[File:marklogic-admin-step1.png]]&amp;lt;br/&amp;gt;&amp;lt;br/&amp;gt;&lt;br /&gt;
#* Click the tab &amp;quot;Create XDBC&amp;quot;&lt;br /&gt;
#** Supply an XDBC server name.&lt;br /&gt;
#*** For the Stack Petstore project, enter &amp;quot;stack-petstore&amp;quot;.&lt;br /&gt;
#** Supply a value for the module directory root.&lt;br /&gt;
#*** For the Stack Petstore project, enter &amp;quot;/&amp;quot;.&lt;br /&gt;
#** Supply a value for the port the XDBC server will listen to for connections.&lt;br /&gt;
#*** For the Stack Petstore project, enter &amp;quot;8010&amp;quot;.&lt;br /&gt;
#** For the modules field, choose &amp;quot;Modules&amp;quot; from the list of options.&lt;br /&gt;
#** Leave all other fields as they are, and click &amp;quot;OK&amp;quot; at the top of the page.&lt;br /&gt;
#*; &amp;lt;br/&amp;gt;[[File:marklogic-admin-step2.png]]&amp;lt;br/&amp;gt;&amp;lt;br/&amp;gt;&lt;br /&gt;
# To try out your Mark Logic installation, go to [http://localhost:8000 &amp;lt;nowiki&amp;gt;http://localhost:8000&amp;lt;/nowiki&amp;gt;] and login with your admin username.&lt;br /&gt;
&lt;br /&gt;
[[Category:LDS Java Stack]]&lt;/div&gt;</summary>
		<author><name>Bowersmt</name></author>
	</entry>
</feed>