Thursday, August 27, 2020

Wonders of MarkLogic Queries

MarkLogic Query needs every correct set of braces to return correct results. 

When using cts.search(cts.AndQuery[query1(), query2()]) using server side javascript - it was not throwing any error or complaining about braces just returning all the documents in the document store.

Talked to Derek@MarkLogic and he was able to quickly spot the error, a curly brace was missing and that did the trick, he said its a bug in MarkLogic and it will be fixed in upcoming releases.

Corrected the query as cts.search(cts.AndQuery([query1(), query2()])) and it worked like a charm.

Lessons learned, if you query is not working as expected, verify your braces as well.


MarkLogic content store Documents vs named store

All documents created under MarkLogic "Documents" store are universally indexed and can be searched without creating any index manually. However documents created in content store created in MarkLogic other than Documents i.e. "my-content-store", documents are not indexed by default. Appropriate type of indexes need to be created for the fields or path for "my-content-store" document store.

Path range indexes are one of the most common index type that is created to use in enterprise applications.

Path range index example1:  "address/state"

Search documents will be based on either of these: field1/address/state or address/state or field1/field2/address/state

Path range index example2:  "/address/state"

Search documents will be based on exact path : /address/state only

No comments: