Quickstart: Use the Bing Entity Search JavaScript client library
Use this quickstart to begin searching for entities with the Bing Entity Search client library for JavaScript. While Bing Entity Search has a REST API compatible with most programming languages, the client library provides an easy way to integrate the service into your applications. The source code for this sample can be found on GitHub.
Prerequisites
The latest version of Node.js.
To install the Bing Entity Search SDK:
- Run
npm install ms-rest-azure
in your development environment. - Run
npm install @azure/cognitiveservices-entitysearch
in your development environment.
Create and initialize the application
Create a new JavaScript file in your favorite IDE or editor, and add the following requirements.
const CognitiveServicesCredentials = require('ms-rest-azure').CognitiveServicesCredentials; const EntitySearchAPIClient = require('@azure/cognitiveservices-entitysearch');
Create an instance of
CognitiveServicesCredentials
using your subscription key. Then create an instance of the search client with it.let credentials = new CognitiveServicesCredentials('YOUR-ACCESS-KEY'); let entitySearchApiClient = new EntitySearchAPIClient(credentials);
Send a request and receive a response
Send an entities search request with
entitiesOperations.search()
. After receiving a response, print out thequeryContext
, number of returned results, and the description of the first result.entitySearchApiClient.entitiesOperations.search('seahawks').then((result) => { console.log(result.queryContext); console.log(result.entities.value); console.log(result.entities.value[0].description); }).catch((err) => { throw err; });