The Cloud CMS REST API allows for elasticsearch queries against a branch. The API endpoint is
POST /repositories/{repositoryId}/branches/{branchId}/nodes/search
The payload is a JSON object containing a top-level property called "search" which wraps the elasticsearch DSL query.
The JavaScript driver exposes this call on the Branch object using the searchNodes() methods.
Examples:
1) Search for nodes containing the keyword "hello" in any property:
req.branch(function (err, branch) {
branch.trap(function (err) {
return res.status(500).json(err);
}).searchNodes({
search: {
query_string : {
query : "hello"
}
}
}).then(function() {
return res.status(200).json(this.asArray());
});
});
2) The same search but limit the properties searched to the "body" and "title" properties:
req.branch(function (err, branch) {
branch.trap(function (err) {
return res.status(500).json(err);
}).searchNodes({
search: {
fields : ["title", "body"],
query : "hello"
}
}).then(function() {
return res.status(200).json(this.asArray());
});
});
3) The same property limited search but using a different form of search:
req.branch(function (err, branch) {
branch.trap(function (err) {
return res.status(500).json(err);
}).searchNodes({
search: {
query : "title:hello OR body:hello"
}
}).then(function() {
return res.status(200).json(this.asArray());
});
});
4) The same property limited search but further filter the results to nodes of type demo:hero. Note the double underscore in the "__type" property name. See this page for an explanation:
req.branch(function (err, branch) {
branch.trap(function (err) {
return res.status(500).json(err);
}).searchNodes({
search: {
query : "(title:hello OR body:hello) AND (__type:\"demo:hero\")"
}
}).then(function() {
return res.status(200).json(this.asArray());
});
});