我正在尝试使用 rest api 创建一个 node.js 应用程序来查询弹性搜索应用程序云上存在的数据。我遵循了弹性搜索连接的代码
var elasticsearch = require('elasticsearch');
var client = new elasticsearch.Client({
host:'localhost:9200'
});
上面的连接正确连接,如果我添加任何数据,它也会被添加..但我希望数据不被添加到本地主机..我希望我的实际集群有数据..我尝试了下面的代码
var elasticsearch = require('elasticsearch');
var client = new elasticsearch.Client({
cloud: {
id: 'cloud_id',
},
auth: {
username: "username",
password: "pass",
},
});
//data I am trying to add
let data = {
"id": "park_somethign",
"title": "Something",
"description": "Split into the separate Rincon Mountain and Tucson Mountain districts, this park is evidence that the dry Sonoran Desert is still home to a great variety of life spanning six biotic communities. Beyond the namesake giant saguaro cacti, there are barrel cacti, chollas, and prickly pears, as well as lesser long-nosed bats, spotted owls, and javelinas.",
"nps_link": "https://www.nps.gov/sagu/index.htm",
"states": [
"Arizona"
],
"visitors": 838456,
"world_heritage_site": false,
"location": "32.20,-109.5",
"acres": 9215.72,
"square_km": 2271.2,
"date_established": "1997-10-14T05:00:00Z"
}
//this is what I am trying to do
client.index({
index: 'engines',
body: data
}).then(resp => {
return res.status(200).json({
message: "Added Data"
})
}).catch(e => {
console.log(e)
return res.status(500).json({
message: "Error",
e
})
})
上面的代码仍然没有添加数据或从我的云集群中检索数据... Evrrywhere on internet I found only localhost examples.. 请谁能告诉我如何将nodejs直接连接到弹性搜索云集群?