执行elasticsearch的搜索查询时出错

时间:2015-05-07 04:46:35

标签: angularjs

我使用 elasticjs 使用 elasticsearch 。我使用搜索查询来搜索具有特定匹配项的 elasticsearch 中的文档,然后查询返回响应。我想从响应中访问response.hits.max_score,但它会生成类型错误:

  

类型错误:无法获取属性'点击'未定义或null   参考

var serch = function() {
    es.search({
        index: 'index1',
        type: 'type1',
        body: {
            "query": {
                "match_all": {}
            },
        }
    }).then(function(response) {});
    $scope.result = response.hits.max_score;
}

1 个答案:

答案 0 :(得分:0)

将respounse.hits.max_score分配给.then body中可用函数中的$ scope变量。解决方案显示如下代码:     es.search({                         index:'dash',                         类型:“节点”,                         身体: {                         “查询”:                               {                                   “比赛”: {                                     “主机名”:name.hostname                                            }
                              },                              }                            })。then(function(response){                           $ scope.result = response.hits.max_score;
                          });