Angular 和 Elasticsearch 的例子 [英] Example of Angular and Elasticsearch

查看:35
本文介绍了Angular 和 Elasticsearch 的例子的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在寻找一个 AngularJS 和 Elasticsearch 使用新的官方客户端库协同工作的工作示例:elasticsearch.angular.js在 http://www.elasticsearch.org/博客/client-for-node-js-and-the-browser

I'm looking for a working example of AngularJS and Elasticsearch working together using the new official client library: elasticsearch.angular.js that's found at http://www.elasticsearch.org/blog/client-for-node-js-and-the-browser

到目前为止,我发现的示例使用备用客户端或不再工作,因为版本之间发生了一些变化.这让刚接触 AngularJS 和 Elasticsearch 的人很难上手.

So far, the examples I've found use alternate clients or don't work anymore because something has changed between versions. This makes it hard for someone new to AngularJS and Elasticsearch to get started.

具体来说,我正在寻找使用官方客户端通过 AngularJS 访问 Elasticsearch 的Hello World".

To be specific, a "Hello World" of accessing Elasticsearch through AngularJS using the official client is what I'm looking for.

其他人似乎也遇到了同样的问题,因为在官方客户端的 repo 中存在一个请求相同内容的未决问题.https://github.com/elasticsearch/elasticsearch-js/issues/19

Others seem to be having the same problem since there is an open issue requesting the same thing in the repo of the official client. https://github.com/elasticsearch/elasticsearch-js/issues/19

推荐答案

这是一种结合 AngularJS 和 Elasticsearch 来做Hello World"的方法

1) 确保您在本地机器上正确安装了 elasticsearch
按照 说明

2) 测试您本地安装的 elasticsearch
通过在命令行上输入
curl -XGET localhost:9200

3) 在elasticsearch中插入一些测试数据
只需运行此 gist 中的每个命令(通过单击每个命令旁边的小绿色三角形)或者您可以通过在命令行中键入以下内容来手动插入数据:

3) Insert some test data into elasticsearch
Just run each of the commands in this gist (by clicking the little green triangle next to each one) or you can insert data manually by typing the following at the command line:

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(或缩小版)客户端并将其放置在您可以使用 Angular 应用程序的某个位置(同一目录应该很好)

5) Dowload the angular.elasticsearch.js (or the minified version) client and place it somewhere where it is available to you Angular app (same directory should be good)

6) 下载并运行以下代码
http://plnkr.co/edit/vfapGG

您也可以直接从 Plunkr 站点 http://plnkr.co/vfapGG 运行此 Plunk,但是这取决于您的安全设置,因为它需要访问位于 localhost:9200

6) Dowload and run the following code
http://plnkr.co/edit/vfapGG

You may also be able to run this Plunk directly from the Plunkr site http://plnkr.co/vfapGG, but that depends on your security settings since it needs to access your brand new Elasticsearch server at localhost:9200

恭喜!!
您现在拥有了一个可用的 Elasticsearch 后端和 AngularJS 前端.

Congratulations!!
You now have a working Elasticsearch backend and AngularJS frontend.

警告
在投入生产之前,请确保正确保护您的 Elasticsearch 服务器,因为任何有权访问它的人都可以轻松修改或删除您存储的数据,并在不安全的情况下获得对运行 Elasticsearch 服务器的计算机的控制(本质上是 shell 访问)正确.

Warning
Before going into production, be sure to secure your Elasticsearch server properly as ANYONE with access to it can easily MODIFY or DELETE your stored data and gain CONTROL (essentially shell access) of the computer running the Elasticsearch server if it is not secured properly.

这篇关于Angular 和 Elasticsearch 的例子的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆