javascript - ElasticSearch 创建索引类型错误

标签 javascript node.js elasticsearch

我正在使用elasticsearch npm 模块。创建索引会导致类型错误,其消息为:

Unable to build a path with those params. Supply at least index

我使用的代码如下所示:

    var client = new elasticsearch.Client({
        host: 'localhost:9200',
        log: 'trace'
    });

    client.indices.create('myindex', function (err, resp) {
        if (err)
            console.log('failed to create ElasticSearch index, ' + err.message);
        else
            console.log('successfully created ElasticSearch index');
    });

根据index create docs ,我应该能够传递带有索引名称的字符串。我很困惑为什么它通常会失败,以及为什么错误消息引用路径。

最佳答案

create() 的第一个参数必须是一个字典。尝试:

client.indices.create({index: 'myindex'}, function (err, resp) {
    if (err)
        console.log('failed to create ElasticSearch index, ' + err.message);
    else
        console.log('successfully created ElasticSearch index');
});

关于javascript - ElasticSearch 创建索引类型错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28160906/

相关文章:

elasticsearch - elasticsearch查询中的terms-lookup-filter聚合顺序会影响执行时间(效率)吗?

javascript - React 路由器导航栏导航

javascript - 使用 mongoose、express 和 node.js 搜索表单。错误 : can't set headers after they are sent

javascript - 从 firebase 一次设置多个变量的状态

node.js - 无法获取 socket.io.js

javascript - node.js 从 http 请求列表中下载图像到服务器

elasticsearch - Elasticsearch不在术语查询中搜索字段

ruby-on-rails - Rails 5.1 与 ElasticSearch 7.1 重建索引错误

javascript - 等距拓扑排序问题

javascript - 一次打开 1 个内容