exportmarklogicmlcp

export results of MarkLogic query (mlcp, xdmp.save)


I have a simple query that filter documents based on the value of a property and return their results.

eg :

var query = 'Yes'
const jsearch = require('/MarkLogic/jsearch');
const myPaths = { paths: ['/envelope/instance/entity'] };
result = jsearch.documents()
    .where(jsearch.byExample({ property: query }))
    .map({ extract: myPaths })
    .result();

Is it possible to use MLCP or a MarkLogic API to save the results of this query as JSON? Compressed results?

Based on this documentation https://docs.marklogic.com/guide/mlcp/export#id_47556 it is possible to do so. But I don't know how to serialize a query that uses jsearch instead of cts.


Solution

  • You need to first extract jsearch query and serialise it as -query_filter option.

    Then you combine -query_filter and -document_selector option to export the specified node.

    The mlcp options_file translation of your jsearch query is:

    export
    -mode
    local
    -host
    localhost
    -port
    ***
    -username
    ***
    -password
    ***
    -output_file_path 
    ***
    -document_selector
    {path-expression}
    -query_filter
    {"jsonPropertyValueQuery":{"property":["property"], "value":["Yes"]}}