我正在尝试使用 Elasticsearch 创建 NodeJS 应用程序
这是我的代码
<!DOCTYPE html>
<script src="../bower_components/elasticsearch/elasticsearch.js"></script>
<script>
function esPinger() {
var elasticsearch = require('elasticsearch');
var client = elasticsearch.Client({
host: 'localhost:9200',
log: 'trace'
});
client.ping({
// ping usually has a 3000ms timeout
requestTimeout: Infinity,
// undocumented params are appended to the query string
hello: "elasticsearch!"
}, function (error) {
if (error) {
console.trace('elasticsearch cluster is down!');
} else {
console.log('All is well');
alert("YAY");
}
});
}
</script>
<html>
<head>
<title>NodeJS Starter Application</title>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="stylesheets/style.css">
</head>
<body>
<center>
<button onclick="esPinger()">Ping ES</button>
</center>
</body>
</html>
我将elasticsearch客户端安装为
npm install elasticsearch
并且
bower install elasticsearch
在我的项目文件夹中,我可以看到有一个bower_componenets
文件夹包含用于 elasticsearch 的所有 .js 文件,包括elasticsearch.js
现在,当我运行我的页面并单击按钮时,我得到
Uncaught ReferenceError: elasticsearch is not defined
知道为什么吗?我错过了一些配置吗?
供参考,这是我的项目结构的样子
编辑
这是我在检查元素控制台中看到的
怎么可能没有图书馆!