我正在使用 npm elasticsearch,因为出现这样的错误
client.index is not a function
这是我的代码
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"
});
使用您的配置更新 host
和 apiVersion
。
关于node.js - 在Elasticsearch中使用nodejs创建索引时出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42242034/