This package contains an isomorphic SDK for EntitySearchClient.
- Node.js version 6.x.x or higher
- Browser JavaScript
npm install @azure/cognitiveservices-entitysearch
npm install @azure/ms-rest-azure-js
The following sample performs a Bing entity search on the query 'Microsoft Azure'. To know more, refer to the Azure Documentation on Bing Entities Search.
import { EntitySearchClient } from "@azure/cognitiveservices-entitysearch";
import { CognitiveServicesCredentials } from "@azure/ms-rest-azure-js";
async function main(): Promise<void> {
const entitySearchKey = process.env["entitySearchKey"] || "<entitySearchKey>";
const entitySearchEndPoint =
process.env["entitySearchEndPoint"] || "<entitySearchEndPoint>";
const cognitiveServiceCredentials = new CognitiveServicesCredentials(
entitySearchKey
);
const client = new EntitySearchClient(cognitiveServiceCredentials, {
endpoint: entitySearchEndPoint
});
const query = "Microsoft Azure";
client.entities
.search(query)
.then(result => {
console.log("The result is: ");
console.log(result);
})
.catch(err => {
console.log("An error occurred:");
console.error(err);
});
}
main();
- index.html
<!DOCTYPE html>
<html lang="en">
<head>
<title>@azure/cognitiveservices-entitysearch sample</title>
<script src="node_modules/@azure/ms-rest-js/dist/msRest.browser.js"></script>
<script src="node_modules/@azure/cognitiveservices-entitysearch/dist/cognitiveservices-entitysearch.js"></script>
<script type="text/javascript">
const entitySearchKey = "<YOUR_ENTITY_SEARCH_KEY>";
const entitySearchEndPoint = "<YOUR_ENTITY_SEARCH_ENDPOINT>";
const cognitiveServiceCredentials = new msRest.ApiKeyCredentials({
inHeader: {
"Ocp-Apim-Subscription-Key": entitySearchKey
}
});
const client = new Azure.CognitiveservicesEntitysearch.EntitySearchClient(
cognitiveServiceCredentials,
{
endpoint: entitySearchEndPoint
}
);
const query = "Microsoft Azure";
client.entities
.search(query)
.then(result => {
console.log("The result is: ");
console.log(result);
})
.catch(err => {
console.log("An error occurred:");
console.error(err);
});
</script>
</head>
<body></body>
</html>