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; });
Next steps
反馈
https://aka.ms/ContentUserFeedback。
即将发布:在整个 2024 年,我们将逐步淘汰作为内容反馈机制的“GitHub 问题”,并将其取代为新的反馈系统。 有关详细信息,请参阅:提交和查看相关反馈