---
title: "Using the JavaScript driver to run an elasticsearch query"
description: "Optimize Elasticsearch queries using Cloud CMS JavaScript driver for precise results. Learn query crafting via API endpoints. (Support 1.0)"
product: "Support"
version: "1.0"
url: "/documentation/support/1.0/support/all/using-the-javascript-driver-to-run-an-elasticsearch-query"
---

# Using the JavaScript driver to run an elasticsearch query

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](https://gitana.io/documentation/gitana/4.0/engine/search/query-string "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());

});

});
