How do I search for nested content?

Cloud CMS maintains two indexes that are of interest for finding things.  The primary index is the MongoDB index - against which you can run any query you can dream up using the MongoDB DSL.  The secondary index is the Elastic Search index - against which you can run any search you can dream up using the Elastic Search DSL.

For information all kinds of really powerful stuff you can do with this, see:

However, there may be times where you want to run multiple lookups using the above-referenced approaches where one lookup depends on the results of the other lookup.  You can solve this by writing code within your application that makes, say, two API calls.

Suppose for example that you have two content types - Book and Article - and an association type to relate them - Book Contains.  Let's define these as "my:book", "my:article" and "my:contains".

Suppose then that you want to find all Books that contain articles that have the word "twitter" in them.  You can do this by first searching for articles that contain the word "twitter".  And then, second, you can search for books that have "my:contains" relationships to the articles you found.

Programmatically, it might look something like this if you're using the Cloud CMS JavaScript chaining library:

   // start by collecting IDs for articles with the word "twitter" in them
   var articleIds = [];
      "filtered": {
         "query": {
            "query_string": {
               "query": "twitter"
         "filter": {
            "type" : {
               "value" : "my:article"
   }).each(function() {
   }).then(function() {

      // now find "my:contains" associations pointing to the books
      var bookIds = [];
         "_type": "my:contains",
         "target": {
            "$in": articleIds
      }).each(function() {
      }).then(function() {

         // all done!


There are many other ways to do this.  However, this should give you a basic idea of how to run back to back calls that make use of IDs retrieved from the first call to feed into the second.