marklogicmarklogic-9

Search metadata properties (last-modified) of the document using REST API search


I would like to search metadata properties 'last-modified' using REST API search. I have the equivalent cts search which is working in query console.

CTS query in qconsole which is working-

  cts.search(cts.andQuery([
 cts.propertiesFragmentQuery(
    cts.elementRangeQuery(
        xs.QName('prop:last-modified'),'>',
        "2020-04-07T10:22:55-05:00"))
        ]))

Here is the REST API search structured query I am using to execute.

http://localhost:xxxx/v1/search?format=json&pageLength=2000&start=1

{
    "search": {
        "ctsquery": {
            "andQuery": {
                "queries": [
                    {
                        "propertiesFragmentQuery": {
                            "elementRangeQuery": {
                                "property": [
                                    "xsQName('prop:last-modified')"
                                ],
                                "operator": ">",
                                "value": [
                                    {
                                        "type": "dateTime",
                                        "val": "2020-04-07T10:22:55-05:00"
                                    }
                                ]
                            }
                        }
                    }
                ]
            }
        }
    }
}

I am getting the following

error "statusCode": 500, "status": "Internal Server Error", "messageCode": "INTERNAL ERROR", "message": "XDMP-QUERYNODE: cts:query(object-node{\"andQuery\":object-node{\"queries\":array-node{object-node{\"propertiesFragmentQuery\":object-node{...}}}}}) -- Query element object-node{\"elementRangeQuery\":object-node{...}} contains unknown child . See the MarkLogic server error log for further detail."

Is something I am missing in the query or is there any other way to access the properties from REST API?

Thanks.


Solution

  • The error indicates the JSON serialization of the cts.query is invalid.

    One way to figure out the correct serialization is to work in QueryConsole:

    1. Write a cts.search() that returns the expected results for the cts.query()
    2. Wrap the cts.query() in xdmp.toJSON() to produce a serialized object for the cts.query
    3. Use the serialized object as the value of the ctsquery key in the payload

    That should get past the XDMP-QUERYNODE error.

    Hoping that helps,