您可以使用“@elastic/elasticsearch” Node.js库来与AWS Opensearch客户端交互。以下是使用此库进行查询的示例代码:
const { Client } = require('@elastic/elasticsearch'); const client = new Client({ node: 'https://your_opensearch_endpoint' });
async function search(indexName, query) { const response = await client.search({ index: indexName, body: { query: { match: { field_name: query } } } }); console.log(response.hits.hits); }
search('your_index_name', 'your_search_query');
请务必将“your_opensearch_endpoint”和“your_index_name”替换为您的AWS Opensearch端点和索引名称。这将执行一个简单的查询并打印结果数组。