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",""))
])
);
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", "")matchesORDERNUMBER: ""andORDERNUMBER: [""].cts.jsonPropertyValueQuery("ORDERNUMBER", null)matchesORDERNUMBER: null.cts.jsonPropertyValueQuery("ORDERNUMBER", "?*", "wildcarded")matchesORDERNUMBER: null(not sure why),ORDERNUMBER: "xx", andORDERNUMBER: ["xx"], but only if you enable filtering (which requirescts.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:HTH!