const axios = require('axios'); // Configuration const serviceName = 'YOUR_SERVICE_NAME'; // Replace with your ACS service name const indexName = 'YOUR_INDEX_NAME'; // Replace with your index name const apiKey = 'YOUR_API_KEY'; // Replace with your admin or query API key // Azure Cognitive Search Endpoint const endpoint = `https://${serviceName}.search.windows.net/indexes/${indexName}/docs`; // API Version const apiVersion = '2021-04-30-Preview'; // Adjust based on your ACS version // Function to perform a search query async function searchAzureCognitiveSearch(query) { try { const response = await axios.get(endpoint, { headers: { 'Content-Type': 'application/json', 'api-key': apiKey, // Use your Azure Cognitive Search API key }, params: { 'api-version': apiVersion, search: query, // The search term or query }, }); // Display the search results console.log('Search Results:', response.data); } catch (error) { console.error('Error querying Azure Cognitive Search:', error.response?.data || error.message); } } // Perform a search query const searchQuery = '*'; // Wildcard search to return all documents searchAzureCognitiveSearch(searchQuery);
|
No comments:
Post a Comment