I'm trying to plot data stored in Elasticsearch using AngularJS client
This is my html and js code.
I have no idea about the wrong thing:
es_connect.js
// We define an EsConnector module that depends on the elasticsearch module
var EsConnector = angular.module('EsConnector', ['elasticsearch']);
EsConnector.service('es', function (esFactory) {
return esFactory({ host: 'http://localhost:9200' });
});
// We define an Angular controller that returns the server health
// Inputs: $scope and the 'es' service
EsConnector.controller('ServerHealthController', function($scope, es) {
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
EsConnector.controller('QueryController', function($scope, es) {
// search for documents
es.search({
index: 'boxes',
type: 'boxid',
body: {
"query": {
"bool": {
"must": [
{
"term": {
"boxid": ""
}
}
],
"must_not": [ ],
"should": [ ]
}
}
}
}).then(function (body) {
var $scope.body = body.hits.hits;
return $scope.body;
})
});
Index.html
<!doctype html>
<html ng-app="EsConnector">
<head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
<script src="https://code.jquery.com/jquery-2.2.1.min.js"></script>
<script type="text/javascript" src="angular.min.js"></script>
<script type="text/javascript" src="angular.js"></script>
<script type="text/javascript" src="elasticsearch.angular.js"></script>
<script type="text/javascript" src="es_connect.js"></script>
</head>
<body>
<div ng-controller="QueryController">
<table>
<tr ng-repeat="item in hits">
<td>{{item['_source']['name']}}</td></tr>
</table>
</div>
<div ng-controller="QueryController">
<li>Request took {{Response.took}} ms
<li>Request matched {{Response.hits.total}} hits
<p>Here is some information on the items returned:</p>
<ul>
<li ng-repeat="item in body.hits.hits">{{item._source.boxid}},{{item._source.shop.updated}}</li>
</ul>
</div>
<br>
Above this line ^^^ should be the results of a test search on the ElasticSearch server.
</body>
</html>
my elasticsearch index is boxes and the index type is boxid.