node.js - 在Elasticsearch中使用nodejs创建索引时出错

标签 node.js elasticsearch

我正在使用 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"
});

使用您的配置更新 hostapiVersion

关于node.js - 在Elasticsearch中使用nodejs创建索引时出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42242034/

相关文章:

node.js - 如何在 Angular 中谨慎使用 localStorage

javascript - 用 Jest 测试 NestJs 服务

python - Node.js child_process.spawn 无法启动 python 进程

elasticsearch - 在 Kibana 上访问 _meta(在 _mapping 中)

elasticsearch - 写重elasticsearch

elasticsearch - 如何将ElasticSearch请求路由到几个分片

javascript - 准确检查一个 bool 选项集

node.js - 使用 grunt 插件调整 4000 多个图像的大小

c# - 使用 NEST 搜索 elasticsearch 索引没有结果

elasticsearch - 完成提示TokenStream扩展错误