janvandeklok
janvandeklok

Reputation: 71

how to create query with MarkLogic java API that gets json documents that don't have a specific jsonKey?

I'm new to Marklogic and need to do a quick evalution of Marklogic in (4 day's). I was wondering how I can execute a query, using the java API, that will get me all the json documents that DO NOT have a certain jsonKey?

I'm dazzeld at the moment by the query api and don't know what to use for this. Any help is greatly appreciated!!

Regards

Jan van de Klok

Upvotes: 1

Views: 455

Answers (1)

mblakele
mblakele

Reputation: 7840

So you're trying to use JSON key-value queries as https://docs.marklogic.com/guide/java/searches#id_56295 describes? Those appear to be positive queries only, equivalent to cts:element-value-query terms.

For a more complex query you'd probably use the structured query option, described in the next section of the same guide. You could construct it in XML using the search:not-query and search:value-constraint-query elements. Or use interfaces like http://docs.marklogic.com/javadoc/client/com/marklogic/client/query/StructuredQueryBuilder.NotQuery.html to construct it in Java code.

Another option is to use a simple string query with a defined constraint option, something like cat -mytag:dog. But that means defining mytag as a custom constraint with cts:not-query and cts:element-value-query. I believe you'd have to write that in XQuery. In the long run there's only so much you can do in MarkLogic without using XQuery.

Upvotes: 1

Related Questions