compose-elasticsearch-helloworld-nodejs is a sample Bluemix application which shows you how to connect to an IBM Compose for Elasticsearch for Bluemix service using Node.js.
-
If you do not already have a Bluemix account, sign up here
-
Download and install the Cloud Foundry CLI tool
-
Connect to Bluemix in the command line tool and follow the prompts to log in.
$ cf api https://api.ng.bluemix.net
$ cf login
- Clone the app to your local environment from your terminal using the following command:
git clone https://github.com/IBM-Bluemix/compose-elasticsearch-helloworld-nodejs.git
-
cdinto this newly created directory -
Open the
manifest.ymlfile.
- Change the
hostvalue to something unique. The host you choose will determinate the subdomain of your application's URL:<host>.mybluemix.net. - Change the
namevalue. The value you choose will be the name of the app as it appears in your Bluemix dashboard.
- If you have already created a Compose for Elasticsearch service in Bluemix, update the
servicevalue inmanifest.ymlto match the name of your service. If you don't already have a Compose for Elasticsearch service in Bluemix, you can create one now using thecreate-servicecommand.
-
Note : The Compose for Elasticsearch service does not offer a free plan. For details of pricing, see the Pricing Plans section of the Compose for Elasticsearch service in Bluemix.
-
You will need to specify the service plan that your service will use, which can be Standard or Enterprise. This readme file assumes that you will use the Standard plan. To use the Enterprise plan you will need to create an instance of the Compose Enterprise service first. Compose Enterprise is a service which provides a private isolated cluster for your Compose databases. For information on Compose Enterprise and how to provision your app into a Compose Enterprise cluster, see the Compose Enterprise for Bluemix help.
Create your service:
$ cf create-service compose-for-elasticsearch Standard my-compose-for-elasticsearch-service
- Push the app to Bluemix. When you push the app it will automatically be bound to the service.
$ cf push
Your application is now running at <host>.mybluemix.net.
The node-elasticsearch-helloworld app displays the contents of an examples Elasticsearch index. To demonstrate that the app is connected to your service, add some words to the index. The words are displayed as you add them, with the most recently added words displayed first.
| File | Description |
|---|---|
| server.js | Establishes a connection to the Elasticsearch index using credentials from VCAP_ENV and handles create and read operations on the index. |
| main.js | Handles user input for a PUT command and parses the results of a GET command to output the contents of the Elasticsearch index. |
The app uses a PUT and a GET operation:
-
PUT
- takes user input from main.js
- uses the
client.indexmethod to add user input to the index
-
GET
- uses the
client.searchmethod to retrieve the contents of the words type - returns the response to main.js
- uses the
The sample web application includes code to track deployments to Bluemix and other Cloud Foundry platforms. The following information is sent to a Deployment Tracker service on each deployment:
- Application Name (application_name)
- Space ID (space_id)
- Application Version (application_version)
- Application URIs (application_uris)
This data is collected from the VCAP_APPLICATION environment variable in IBM Bluemix and other Cloud Foundry platforms. This data is used by IBM to track metrics around deployments of sample applications to IBM Bluemix. Only deployments of sample applications that include code to ping the Deployment Tracker service will be tracked.
Deployment tracking can be disabled by removing require("cf-deployment-tracker-client").track(); from the beginning of the server.js file.