Loading repository data…
Loading repository data…
IBM / repository
Develop a fully featured Node.js web app built on the Watson Discovery Service
Read this in other languages: 日本.
Note: This code pattern has been updated to work with Watson Discovery V2. Unfortunately, some of the original features of the V1 version are no longer supported and had to be removed - please keep this in mind as you view the source code, documentation and accompanying video.
In this code pattern, we walk you through a working example of a web application that queries and manipulates data from the Watson Discovery Service. This web app contains multiple UI components that you can use as a starting point for developing your own Watson Discovery Service applications.
The main benefit of using the Watson Discovery Service is its powerful analytics engine that provides cognitive enrichments and insights into your data. This app provides examples of how to showcase these enrichments through the use of filters, lists and graphs. The key enrichments that we will focus on are:
For this code pattern, we will be using data that contains reviews of Airbnb properties located in the Austin, TX area.
When the reader has completed this code pattern, they will understand how to:
Here is a rough sketch of the main UI screen, followed by a description of each UI component and their assoicated actions:
Note: see DEVELOPING.md for project structure.
git clone https://github.com/IBM/watson-discovery-ui
To create your Watson Discovery service:
Click Create resource on your IBM Cloud dashboard.
Search the catalog for discovery.
Click the Discovery tile to launch the create panel.
Enter a unique name, select a location, and select the default Plus plan.
NOTE: The first instance of the Plus plan for IBM Watson Discovery comes with a free 30-day trial. If you no longer require your Plus instance for Watson Discovery after going through this exercise, you can delete it.
From the Discovery instance page, click Launch Watson Discovery.
The landing page for the Discovery service shows you a list of current projects. Click New project.
Give the project a unique name and select the Document Retrieval option, then click Next.
The next step is telling Discovery where your data will come from. In this code pattern, we will be uploading the data from JSON data files, so click Upload data, and then click Next.
Enter a collection name, then click Next.
NOTE: The Watson Discovery service queries are defaulted to be performed on all collections within a project. For this reason, it is advised that you create a new project to contain the collection we will be creating for this code pattern.
To load our AirBnB reviews, click on Drag and drop files here or upload button to select and upload the JSON review files located in your local data/airbnb directory.
When you complete the action, click Finish.
Be patient as the data files are uploaded. Discovery provides alerts to tell you when the upload is complete.
Click Manage collections on the left to show all of the collections associated with your project.
Note: To change which project you are currently working on, you can click
My projectsat the top of the page.
When you click the collection that you just created, you will see that all 999 reviews have been loaded.
Select the Enrichments tab. As you can see, the default enrichments are Part of speech and Entities v2. For this review data, you are also going to include Keywords and Sentiment of Document.
For each of these new enrichments, click Fields to enrich, and select the text field.
Click Apply changes and reprocess to add the enrichments.
Next, you'll need to add the Watson Discovery credentials to the .env file.
From the home directory of your cloned local repo, create a .env file by copying it from the sample version.
cp env.sample .env
Locate the service credentials listed on the home page of your Discovery service and copy the API Key and URL values.
You also need your project ID, which you can get from the Watson Discovery Integrate and deploy panel for your project.
Take the copied values and paste them into the .env file:
# Copy this file to .env and replace the credentials with
# your own before starting the app.
# Watson Discovery
DISCOVERY_PROJECT_ID=0a3f4e2d-bb5e-9999-8888-631535710b06
DISCOVERY_APIKEY=hyZeFTi9g_zzzzzzzz-1TG6p0V2hEoVuaAG56
DISCOVERY_URL=https://api.us-south.discovery.watson.cloud.ibm.com/instances/40b3d31e-9999-8888-fd24e28a1f7b
# Run locally on a non-default port (default is 3000)
# PORT=3000
Install Node.js runtime or NPM.
Then run:
npm install
npm start
The application will be available in your browser at http://localhost:3000.
NOTE: The server host can be changed as required in app.js and
PORTcan be set in the.envfile.
Note that each review will be truncated to 200 characters or less. A more... button will be provided for each review, and when clicked, the full review title and text will be displayed in a pop-up modal window, as shown below:
Error: Environment {GUID} is still not active, retry once status is active
This is common during the first run. The app tries to start before the Discovery environment is fully created. Allow a minute or two to pass. The environment should be usable on restart. If you used
Deploy to IBM Cloudthe restart should be automatic.
Error: Only one free environment is allowed per organization
To work with a free trial, a small free Discovery environment is created. If you already have a Discovery environment, this will fail. If you are not using Discovery, check for an old service thay you may want to delete. Otherwise use the .env DISCOVERY_ENVIRONMENT_ID to tell the app which environment you want it to use. A collection will be created