You want to find all JSON documents that are missing a particular property.
Applies to MarkLogic versions 8+
cts.search( cts.notQuery( cts.jsonPropertyScopeQuery( "target", cts.trueQuery() ) ) )
cts:search( fn:doc(), cts:not-query( cts:json-property-scope-query( "targetElement", cts:true-query() ) ) )
MarkLogic’s built-in search engine uses query criteria to identify matching fragments. The indexes map terms (words, phrases, structures, etc.) to fragment identifiers. To run a search, the specified terms are looked up in the appropriate index to find fragment identifiers. In the case of cts:not-query, the search will return any fragment identifiers except those matched by the nested query.
cts:json-property-scope-query is a useful way to constrain a search to part of a document. The function restricts the nested query to matching within the specified JSON property.
The cts:true-query query passed to cts:json-property-scope-query
does what it sounds like — it matches everything. Passed to cts:json-property-scope-query
, this provides a simple way to test for the existence of an element.1
By continuing to use this website you are giving consent to cookies being used in accordance with the MarkLogic Privacy Statement.