Search This Blog

Friday, April 14, 2017

How to use Watson Discovery service ?


In this tutorial I will show you how to use Watson Discovery service locally and how to push an app to Blue mix using the cloud foundry command line tools( Node JS version)


image

Prerequisites:
  • Node JS
  • Visual Code
  • Blue mix account (Setup free account for 30 days)
  • Cloud foundry CLI

Step 1 Clone Repo or download as zip from Github
https://github.com/watson-developer-cloud/discovery-nodejs.git

Step 2 Go to that folder rename .env.example to .env ( It should have place holders for username and password etc)
This file need to be updated with the discovery service username and password, it also needs a discovery environment and the collection id( Watson news collection in our case)




Watson already has a set of news collection and we will be using to discover news and sentiments in this demo.
image

Step 3
Now we will see how to get the above credentials.
Go to command prompt and navigate to your downloaded folder.

\discovery-nodejs-master cf login  

\discovery-nodejs-master cf push

Currently we are directly pushing our app to blue mix and it will create an application as mentioned in the manifest.yml.

Ref.


image

In this case I am trying to tell blue mix to provision an application in cloud with application name as “discovery-news-demo101”  and attach a service to it by the name of “my-discovery”

After to login with your email id and password, it will check with you on which space you want to use( Space could be DEV/TEST/PROD its a virtual name for a workspace)

image
Wait for a while, you will see an app created in blue mix and a service attached to it.

Now go to that service and add a new credential to it, copy the username/password and insert it into .env file.

Now the missing piece to complete our .env file are:
  • Environment id
  • Collection id

We will fire CURL to blue mix to get these details.

Fire this to get the Environment created for us.
curl -X GET -u <username>:<password> https://gateway.watsonplatform.net/discovery/api/v1/environments?version=2016-11-07

From the response, get the environment id and fire another curl request.

curl -X GET -u <username>:<password> https://gateway.watsonplatform.net/discovery/api/v1/environments/bb6ffe96-53d5-44b3-8838-922d4665df8d/collections?version=2016-11-07

Now you will get collection id.

Now enter these two details also in our .env file and now its time to push our app again.

Go to command prompt and push it
> cf push

It will upload your app on blue mix and you can check it in the browser.

image




You can also test it locally by installing node dependencies and starting a local node js server.
Go to your folder
> npm install ( to install dependencies)
> npm start


blue mix cloud foundry git hub push
discovery service watson nodejs

3 comments:

  1. Hello, sorry I have issues with the Discovery service

    what extension should the .env have?

    because I have set everything in my bluemix account and all and despite the app is online I cannot search for anything in the app, it searchs nothing.

    Thanks

    ReplyDelete
  2. Neverming Engineers. I found the extension for the archive.

    Thanks.

    ReplyDelete