这是一种结合 AngularJS 和 Elasticsearch 来做“Hello World”的方法
1) 确保您已在本地计算机上正确安装了elasticsearch
遵循指示 http://www.elasticsearch.org/overview/elkdownloads/
2) 测试本地安装的elasticsearch
通过在命令行中输入
curl -XGET localhost:9200
3) 向elasticsearch中插入一些测试数据
只需运行其中的每个命令即可gist http://sense.qbox.io/gist/5d760c460b8d5ba4f6f7c51bc6bcab55174146aa(点击每个旁边的绿色小三角形)
或者您可以通过在命令行中键入以下内容来手动插入数据:
curl -XPUT "http://localhost:9200/test_index/product/1" -d '{
"title": "Product1",
"description": "Product1 Description",
"price": 100
}'
curl -XPUT "http://localhost:9200/test_index/product/2" -d '{
"title": "Product2",
"description": "Product2 Description",
"price": 200
}'
4) 测试从elasticsearch检索数据
curl -XGET localhost:9200/test_index/product/1
5) 下载Angular.elasticsearch.js http://www.elasticsearch.org/guide/en/elasticsearch/client/javascript-api/current/about.html#_browser_builds(或缩小版本)客户端并将其放置在 Angular 应用程序可用的地方(同一目录应该很好)
6) 下载并运行以下代码
http://plnkr.co/edit/vfapGG http://plnkr.co/edit/vfapGG
您也可以直接从 Plunkr 站点运行此 Plunkhttp://plnkr.co/vfapGG http://plnkr.co/vfapGG,但这取决于您的安全设置,因为它需要访问您全新的 Elasticsearch 服务器localhost:9200
恭喜!
您现在已经有了一个可以运行的 Elasticsearch 后端和 AngularJS 前端。
Warning
在投入生产之前,请确保正确保护您的 Elasticsearch 服务器,因为任何有权访问该服务器的人都可以轻松修改或删除您存储的数据,并获得对运行 Elasticsearch 服务器的计算机的控制(本质上是 shell 访问)(如果没有正确保护)。