繁体   English   中英

Nodejs Elasticsearch错误未显示

[英]Nodejs Elasticsearch errors are not showing

我遇到了nodejs elasticsearch库的问题。 如果我删除console.log(hello);下面的代码正在工作并给出结果 但是,如果添加此内容,则不会出现错误。 我期待未定义变量“ hello”的错误消息。 我需要查看错误消息以进行调试。 可能是什么原因?

var elasticsearch = require('elasticsearch');
var esClient = new elasticsearch.Client({
  host: 'http://mywebsite.com',
  // log: 'trace'
});


body = {};

esClient.search({
          index: 'test',
          type: 'data',
          body: body
        }).then(function (resp) {

            console.log(hello);
            console.log(resp);    
});

您确定代码到达了then函数内部吗? 也许搜索抛出错误并且您没有catch块?

尝试:

esClient.search({...})
        .then(function (resp) {

            console.log(hello);
            console.log(resp);    
        })
        .catch(function(error){
            console.log(error);    
        });

看看是否有任何错误呢?

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM