setup cq on marklogic server

Now that we’ve installed MarkLogic Server, we’ll want a quick and convenient way to interact with our content and to explore MarkLogic features. A great tool for this job is cq.

cq is a web-based XQuery tool, which will allow us to write ad hoc queries directly in a browser that we can then evaluate against a MarkLogic database.

cq is super useful, super cool, super fun, super free, and pretty much the first thing anyone working with MarkLogic Server installs.

MarkLogic recently announced the release of MarkLogic Server 4.1.  cq actually now ships with 4.1 and is made available after installation of the Server through a simple configuration in the Admin UI.  Since our previous demonstration was an express install of 4.0-5, I’m going to show you how to set up and install cq on both versions.

install cq on 4.0-5

When we installed MarkLogic Server, it actually preconfigured a HTTP Application Server and a Database for us.  The name of the Server is Docs and it is running on port 8000.  The Database is named Documents and it is set as the database for the Docs server.  All we need to do is throw cq in the  root directory of our App Server and we’ll then have a convenient way to interact with content in the Documents database.

1) Download cq

You’ll find cq on the Developer Workshop.  For 4.0-5 you’ll want the mark-logic-cq-4.0-4.zip release.

2) Unzip the file you just downloaded.

3) Copy the cq directory within the unzipped mark-logic-cq-4.0-4 directory to the Server root:

On windows copy the cq directory to C:\Program Files\MarkLogic\Docs\cq

On linux copy the cq directory to /opt/MarkLogic/Docs/cq

4) Start cq

Launch your favorite browser and enter the following URL: http://localhost:8000/cq

We’ll be prompted for our MarkLogic Server credentials.  After entering our username and password,  cq opens and we now have an interface for interacting with the Documents database in MarkLogic Server.

cq 101

cq is divided into two major sections. The top half contains an area for entering queries as well as a list of selectable buffers.   The default query screen, from top to bottom, includes:

  • an XQuery version declaration
  • a comment that includes the buffer number
  • a html namespace declaration
  • a simple XML element <p>hello world</p>.

Above the query area we see two links: explore and session. Clicking explore will return uris from documents stored in the selected content source and display them in the bottom half of the browser.  Click session to learn more about sessions and to start, save, or resume one.

Underneath the  query area are a dropdown for the available content sources and 4 buttons.  The dropdown has selected the Documents database for us by default, so we’ll leave that for now.  Just click the XML button to see the XML view of the evaluated query displayed in the bottom half of the browser.


Also note the lower right corner of the query area. If you rollover that area,  you can get a handle to drag and adjust the size of the query area.  Likewise, if you rollover the bar between the query area and the XML results, you can drag and adjust the size of your results area as well.  These options can come in handy when working with large queries or examining large result sets.

configure cq on 4.1-1

cq ships with 4.1 and is made available as a Sample application.  To make cq available on a freshly installed 4.1 MarkLogic Server just:

  • Open the Admin UI by entering the url http://localhost:8001 in your browser
  • Navigate in the tree in the left pane to Groups -> Default -> App Servers -> Docs
  • Change the value in the root directory field from Docs/ to Samples/
  • Click ok


You can now use CQ by entering the following url in a browser: http://localhost:8000/cq

NOTE: The version of cq that ships with 4.1, is not the 4.0-4 version, but a 4.1-1 version.  If you’re copying cq to multiple servers, make sure to use the version of cq that correlates with the Server version.

next steps

Boom! That’s it. You’ve installed cq.  Next we want to start loading up our database and running some queries to do something useful. We’ll start next post by exploring Twitter using cq. If you want to keep playing along at home, go sign up and get a Twitter account if you don’t already have one.


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s


%d bloggers like this: