elasticsearch angular js error -1

时间:2017-08-29 01:50:57

标签: angularjs elasticsearch

我希望在使用angular js

的网页上显示弹性搜索数据

我运行此代码文件,但出现错误消息,如“error:-1”。

我很好奇这个文件的某些部分发生了错误。

如果有人回答我,我真的很感激

我附上了执行屏幕。

谢谢。

执行屏幕:

屏幕截图1:

enter image description here

截屏2:

enter image description here

<!doctype html>
<html ng-app="myApp">
<head>
     <meta http-equiv="content-type" content="text/html; charset=UTF-8">
</head>
<body>

<div ng-controller="QueryController"></div>

<script src="node_modules/angular/angular.js"></script>
<script src="node_modules/elasticsearch-browser/elasticsearch.angular.js"></script>

<script>


    var myApp = angular.module('myApp', ['elasticsearch']);

    // Create the es service from the esFactory


    myApp.service('es', function (esFactory) {
        return esFactory({ host: "http://localhost:9200"});
    });

    myApp.controller('ServerHealthController', function($scope, es, esFactory) {

        es.cluster.health(function (err, resp) {
            if (err) {
                $scope.data = err.message;

            } else {
                $scope.data = resp;

            }
        });
    });

    // We define an Angular controller that returns query results,
    // Inputs: $scope and the 'es' service

    myApp.controller('QueryController', function($scope, es, esFactory) {

// search for documents
        es.search({

            index: 'epowersyst',
            type: 'logs',
            body: {
              query:
                {
                  match_all : {} }
                }

        }).then(function (response) {
            $scope.hits = response;
            console.log($scope.hits)

        }).catch(function (err) {
          if (err.status === 404) {
            alert("error 404" );

          } else {
            alert("error : " + err.status );

          }
        });

    });
</script>
</body>
</html>

0 个答案:

没有答案