<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
<script src="https://cdn.bootcss.com/angular.js/1.3.2/angular.min.js"></script>
<script src="https://cdn.bootcss.com/elasticsearch/2.4.1/elasticsearch.angular.min.js"></script>
</head>
<body ng-app="ExampleApp">
<div class="container" ng-controller="ExampleController">
<p>hello</p>
</div>
<script>
// App module
//
// The app module will contain all of the components the app needs (directives,
// controllers, services, etc.). Since it will be using the components within
// the elasticsearch module, define it a dependency.
var ExampleApp = angular.module('ExampleApp', ['elasticsearch']);
// Service
//
// esFactory() creates a configured client instance. Turn that instance
// into a service so that it can be required by other parts of the application
ExampleApp.service('client', function (esFactory) {
return esFactory({
host: 'http://db.irocn.com:8864',
// apiVersion: '1.3', //可以忽略不写
// log: 'trace'//可以忽略不写
});
});
// Controller
//
// It requires the "client" service, and fetches information about the server,
// it adds either an error or info about the server to $scope.
//
// It also requires the esFactory to that it can check for a specific type of
// error which might come back from the client
ExampleApp.controller('ExampleController', function ($scope, client, esFactory) {
// 搜索文档
var name = "陈大勇";
client.search({
index: 'filecoin_users',
size: 50,
body: {
query: {
match: {
username : name
}
}
}
}).then(function (resp) {
console.log(resp);
// $("#message").append("search data total num : " + resp.hits.total + "<br\>");
});
});
</script>
</body>
</html>