我已经运行了elasticsearch.bat,并在浏览器中用localhost:9200查询了这个。JSON对象返回如下,所以到目前为止一切正常。
{
"status" : 200,
"name" : "hwils_01_dev",
"cluster_name" : "elasticsearch_hwils_dev",
"version" : {
"number" : "1.7.2",
"build_hash" : "e43676b1385b8125d647f593f7202acbd816e8ec",
"build_timestamp" : "2015-09-14T09:49:53Z",
"build_snapshot" : false,
"lucene_version" : "4.10.4"
},
"tagline" : "You Know, for Search"
} 我已经下载并通过标签链接到我的index.html the elasticsearch.js
<script src="elasticsearch-js/elasticsearch.js"></script>(顺便说一句,下载中有超过1个.js -我需要将它们都链接起来吗?)
然后,我将代码添加到另一个标记中
var client = new elasticsearch.Client({
host: 'localhost:9200',
log: 'trace'
});并将其输出到控制台-再次返回JSON对象,大概到目前为止一切正常。
如果我随后运行
client.ping({
requestTimeout: 30000,
// undocumented params are appended to the query string
hello: 'elasticsearch'
}, function (error) {
if (error) {
console.error('elasticsearch cluster is down!');
} else {
console.log('All is well');
}
});我得到返回的错误消息。我也不知道为什么。
顺便说一句
var elasticsearch = require('elasticsearch');返回“未捕获引用错误:未定义要求”,这表明该函数至少缺少一个其他.js文件?
发布于 2015-10-15 17:07:02
由于您使用的是浏览器,因此需要使用browser build (目前可以使用Angular或jQuery )。
假设你用jQuery的方式,你的<script>应该是这样的:
<script src="elasticsearch-js/elasticsearch.jquery.min.js"></script>然后你可以像这样创建你的客户端:
var client = new $.es.Client({
hosts: 'localhost:9200',
log: 'trace'
});发布于 2015-10-15 17:26:20
require语句是仅限NodeJS的函数。您需要下载ES的浏览器版本并在您的HTMl文件中引用,正如Val提到的那样。
https://stackoverflow.com/questions/33144058
复制相似问题