3

Structure of JSON documents required to be searched in Marklogic

{  
   "MESSAGEID":"18878285",
   "ORDERNUMBER":["2295796"],
   "CATEGORY":"F3702200000"
}

I wanted to search the URIs of all JSON documents in Marklogic that comprised of not null ORDERNUMBER using Javascript

I am using the following query but it is still showing the URIs for the documents comprising of "ORDERNUMBER":[]

cts.uris("",null,cts.andQuery
    ([
        cts.jsonPropertyValueQuery("ORDERNUMBER", "*", "wildcarded"),
        cts.notQuery(cts.jsonPropertyValueQuery("ORDERNUMBER",""))
    ])
);

1 Answer 1

4

You normally have a few options, but the empty array case is particularly hard to distinguish. This is because it is neither an empty string value, nor a null, yet the property is truly present.

cts.jsonPropertyScopeQuery("ORDERNUMBER", cts.trueQuery()) will match any doc that has that property.

cts.jsonPropertyValueQuery("ORDERNUMBER", "") matches ORDERNUMBER: "" and ORDERNUMBER: [""].

cts.jsonPropertyValueQuery("ORDERNUMBER", null) matches ORDERNUMBER: null.

cts.jsonPropertyValueQuery("ORDERNUMBER", "?*", "wildcarded") matches ORDERNUMBER: null (not sure why), ORDERNUMBER: "xx", and ORDERNUMBER: ["xx"], but only if you enable filtering (which requires cts.search), or if you are able to find the appropriate wildcard settings.

To be honest, the simplest solution to my opinion is to just put a range index on ORDERNUMBER, and use a rangeQuery:

cts.rangeQuery(cts.pathReference('ORDERNUMBER'), '>', '')

HTH!

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.