Searching a Cloudant DB search index with Node-Red

After much searching the internet and seeing multiple posts about this subject I can only think that many others are greatly confused with the use of the Cloudant In node in Node-Red. I think my problem was terminology and not being familiar enough with the Cloudant nomenclature more than anything and the user interface in Node needs a little more work.

I basically want to return all documents where name=XXXXX. My document is pretty simple, here is an example:

review-doc

So lets start by looking at my index definition:

cloudant_index

Now you will notice I have three references to “namesearch”:

  1. The design document name is “_design/namesearch”
  2. The Index name is “nameSearch”
  3. The index in the search index function is also named “nameSearch”

My flow takes in an HTTP request, formats it with the Selector node, and passes the query on to the Cloudant In node:

flow

The selector node is pretty basic, after following many different instructions I finally resolved the problems with this function:

selector

This results in a payload that looks like this:

nameSearch:Create a category layout

The Cloudant In node now has the following configuration (which seemed to be the primary problem, I will explain later:

cloudantin

The problem I had was I could not future out the search index fields. Mainly because this is the form when no fields are filled in:

designdoc

Notice it specifically says “design document“. Now, anyone that is not familiar with this, based on my configuration, would most likely fill it out like this:

node-red cloudant in

But after scouring many documents on the internet a suggestion was to just remove the “_design/” from the first field. Which resulted in the correct version I have above:

cloudantin

Needless to say this actually took me hours to figure out because I thought it was something with the query being passed in!

If you are not familiar with Node-Red then click this link.

2 thoughts on “Searching a Cloudant DB search index with Node-Red

  1. but how do you return results to the original HTTP request. Looks like the HTTP response always returns a 200 OK, without including any results. Wiping out the msg.payload removes all the HTTP meta data required for the HTTP response.

    Like

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s