ElasticSearch创建索引TypeError

时间:2015-01-26 23:46:35

标签: javascript node.js elasticsearch

我正在使用elasticsearch npm模块。创建索引会导致TypeError的消息为:

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,我应该能够传递一个带有索引名称的字符串。我很困惑为什么它一般会失败,以及为什么错误消息指的是路径。

1 个答案:

答案 0 :(得分:2)

create()的第一个参数需要是dict。尝试:

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');
});