在Elasticsearch中使用nodejs创build索引时出错

我正在使用npm elasticsearch,因为得到这样的错误

client.index不是一个函数

这是我的代码

encryptObj = enpyt.encrypt(function(encrypted){ client.index({ index: 'collectionnew3 id: '101', type: 'collectiontype3', body: { "username": "postgres", "pswrd": encrypted, } },function(err,resp,status) { console.log(resp); }) }) 

任何想法,为什么我得到这个?

正如评论所说,似乎client没有正确实例化。

在node.js中实例化Elasticsearch客户端的示例:

 var elasticsearch = require('elasticsearch'); var client = new elasticsearch.Client({ host: "http://localhost:9200", apiVersion: "2.3" });