const { SearchClient, AzureKeyCredential } =
require('@azure/search-documents');
// Replace with your Azure Cognitive
Search service endpoint and API key const endpoint =
'https://<your-search-service-name>.search.windows.net'; const apiKey = '<your-api-key>';
// Replace with your index name const indexName = '<your-index-name>';
// Create a search client const
searchClient = new SearchClient(endpoint, indexName, new
AzureKeyCredential(apiKey));
async
function searchByEnterpriseId(enterpriseId) { try {
// Create a
search query const searchOptions = { filter: `enterpriseId
eq '${enterpriseId}'` };
// Perform the search const searchResult = await
searchClient.search('*', searchOptions); // Process the results let results = []; for await (const result of
searchResult.results) { results.push(result); } console.log('Search results:', results);
} catch (error) { console.error('Error occurred during
search:', error); } }
// Example usage const
enterpriseIdToSearch = 'your-enterprise-id';
// Replace with the actual enterprise ID you
are searching for searchByEnterpriseId(enterpriseIdToSearch);
|
No comments:
Post a Comment