Do not use QueryOptionsBuilder as it is deprecated. Instead use your favorite XML builder API. XML builder libraries for Java are prevalent and several good ones are directly supported by the Java Client API: Jackson<https://docs.marklogic.com/javadoc/client/com/marklogic/client/io/JacksonHandle.html>, JDOM<https://docs.marklogic.com/javadoc/client/com/marklogic/client/extra/jdom/JDOMHandle.html>, DOM4J<https://docs.marklogic.com/javadoc/client/com/marklogic/client/extra/dom4j/DOM4JHandle.html>, XOM<https://docs.marklogic.com/javadoc/client/com/marklogic/client/extra/xom/XOMHandle.html>, DOM<https://docs.marklogic.com/javadoc/client/com/marklogic/client/io/DOMHandle.html>, and JAXB<https://docs.marklogic.com/javadoc/client/com/marklogic/client/io/JAXBHandle.html>. Pick your favorite.
Also, there are XML Builders that create an InputStream or String and can thus be supported using StringHandle<https://docs.marklogic.com/javadoc/client/com/marklogic/client/io/StringHandle.html> or InputStreamHandle<https://docs.marklogic.com/javadoc/client/com/marklogic/client/io/InputStreamHandle.html>. For an example, you could use XMLStreamWriter: ByteArrayOutputStream baos = new ByteArrayOutputStream(); XMLOutputFactory factory = XMLOutputFactory.newInstance(); factory.setProperty(XMLOutputFactory.IS_REPAIRING_NAMESPACES, true); XMLStreamWriter w = factory.createXMLStreamWriter(baos, "UTF-8"); w.setDefaultNamespace("http://marklogic.com/appservices/search"<http://marklogic.com/appservices/search>); w.writeStartElement("options"); w.writeStartElement("constraint"); w.writeAttribute("name", "tag"); w.writeStartElement("collection"); w.writeEndElement(); w.writeEndElement(); w.writeStartElement("constraint"); w.writeAttribute("name", "company"); w.writeStartElement("value"); w.writeAttribute("type", "string"); w.writeStartElement("json-property"); w.writeCharacters("affiliation"); w.writeEndElement(); w.writeEndElement(); w.writeEndElement(); w.writeEndElement(); System.out.println( baos.toString("UTF-8") ); Sam Mefford Senior Engineer MarkLogic Corporation sam.meff...@marklogic.com<mailto:sam.meff...@marklogic.com> Cell: +1 801 706 9731 www.marklogic.com<http://www.marklogic.com> This e-mail and any accompanying attachments are confidential. The information is intended solely for the use of the individual to whom it is addressed. Any review, disclosure, copying, distribution, or use of this e-mail communication by others is strictly prohibited. If you are not the intended recipient, please notify us immediately by returning this message to the sender and delete all copies. Thank you for your cooperation. On 2/22/2016 4:08 AM, Hamza Bennani wrote: Hi, I'm new to MarkLogic and I'm facing a problem when I try to define a JSON key/value constraint via the Java REST API client. I'm using MarkLogic v8 My Java code is : QueryOptionsManager optionsMgr = client.newServerConfigManager().newQueryOptionsManager(); QueryOptionsBuilder qob = new QueryOptionsBuilder(); QueryOptionsHandle optsHandle = new QueryOptionsHandle().withConstraints( qob.constraint("tag", qob.collection(""))); // add a JSON value constraint optsHandle.addConstraint( qob.constraint("company", qob.value( qob.jsonTermIndex("affiliation")))); The error thrown is : Status 500: RESTAPI-INVALIDCONTENT: (err:FOER0000) Invalid content: Operation results in invalid Options: Use "json-property" instead of "json-key" to specify structures in JSON. Validation detail: XDMP-VALIDATEUNEXPECTED: (err:XQDY0027) validate strict { $opt } -- Invalid node: Found search:json-key but expected ((((((search:element)|search:attribute)|search:json-property|search:field)|search:fragment-scope)*)|((search:term-option|search:weight)*))* at fn:doc("")/search:options/search:constraint[2]/search:value/search:json-key using schema "search.xsd"An <element>, <json-property> or <field> specification is required on <value>. My question is how to use "json-property" instead of "json-key" as suggested ? Thanks, -- Hamza BENNANI _______________________________________________ General mailing list General@developer.marklogic.com<mailto:General@developer.marklogic.com> Manage your subscription at: http://developer.marklogic.com/mailman/listinfo/general
_______________________________________________ General mailing list General@developer.marklogic.com Manage your subscription at: http://developer.marklogic.com/mailman/listinfo/general