Menu BAR

FEEL FREE TO ASK ANY PROGRAM and please mention any error if you find it

4 Aug 2024

NODE JS CODE TO SEARCH ENTERPRISE ID IN AZURE COGNITIVE SEARCH SERVICE (ACS)


 ## Write a NODEJS Program to SEARCH ENTERPRISE ID in AZURE COGNITIVE SEARCH SERVICE (ACS) 




    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