角和Elasticsearch示例 [英] Example of Angular and Elasticsearch

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

问题描述

我在寻找AngularJS和Elasticsearch共同努力使用新的官方客户端库的工作示例:elasticsearch.angular.js
该公司发现在<一个href=\"http://www.elasticsearch.org/blog/client-for-node-js-and-the-browser\">http://www.elasticsearch.org/blog/client-for-node-js-and-the-browser

到目前为止,我发现使用备用客户或者是因为事情已经更改版本之间不工作了的例子。这使得它很难有人新AngularJS和Elasticsearch上手。

要具体而言,通过使用官方客户端访问AngularJS的Elasticsearch一个Hello World就是我要找的。

其他似乎有同样的问题,因为有要求在官方客户端的回购同样的事情,一个开放的问题。
<一href=\"https://github.com/elasticsearch/elasticsearch-js/issues/19\">https://github.com/elasticsearch/elasticsearch-js/issues/19


解决方案

这是一个方式做一个Hello World结合AngularJS和Elasticsearch

结果搜索结果
1)确保你已经正确安装elasticsearch本地计算机的结果在下面的说明:<一href=\"http://www.elasticsearch.org/overview/elkdownloads/\">http://www.elasticsearch.org/overview/elkdownloads/
结果搜索结果
2)测试本地的安装elasticsearch 结果
通过键入在命令行结果
卷曲-XGET本地主机:9200
结果搜索结果
3)插入一些测试数据为elasticsearch 结果
刚(点击旁边的每一个绿色的小三角形)运行的每个在这种精神的命令
<一href=\"http://sense.qbox.io/gist/5d760c460b8d5ba4f6f7c51bc6bcab55174146aa\">http://sense.qbox.io/gist/5d760c460b8d5ba4f6f7c51bc6bcab55174146aa

或者您可以通过键入在命令行下面的手动插入数据:搜索结果
卷曲-XPUT的http://本地主机:9200 /的test_index /产品/ 1-d{称号:产品1,说明:产品1描述,价格:100 }

卷曲-XPUT的http://本地主机:9200 /的test_index /产品/ 2-d{称号:产品2,说明:产品2描述,价格:200}
结果搜索结果
4)的测试检索从elasticsearch 数据结果
卷曲-XGET本地主机:9200 /的test_index /产品/ 1
结果搜索结果
5)下载中心的<一个href=\"http://www.elasticsearch.org/guide/en/elasticsearch/client/javascript-api/current/about.html#_browser_builds\">angular.elasticsearch.js (或缩小的版本)客户端和地方将其放置在它是提供给你的应用程序角(相同的目录应该是不错的)
结果搜索结果
6)下载中心,然后运行以下code 结果
http://plnkr.co/edit/vfapGG 搜索结果
您还可以直接从网站Plunkr http://plnkr.co/vfapGG 运行此普拉克,但是这取决于你的安全设置,因为它需要在本地主机访问您的全新Elasticsearch服务器:9200
结果搜索结果
恭喜!结果
你现在有一个工作Elasticsearch后端和前端AngularJS。搜索结果
搜索结果
警告
结果在投入生产之前,请务必访问正确保护您的Elasticsearch服务器作为任何人都可以很容易地修改或删除你的存储数据,并获得运行Elasticsearch服务器的计算机控制(主要是shell访问),如果它没有固定正常。

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

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.

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

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

解决方案

Here is a way to do a "Hello World" combining AngularJS and Elasticsearch




1) Make sure you have installed elasticsearch correctly on your local machine
following the instructions at: http://www.elasticsearch.org/overview/elkdownloads/


2) Test your local install of elasticsearch
by typing on the command line
curl -XGET localhost:9200


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) http://sense.qbox.io/gist/5d760c460b8d5ba4f6f7c51bc6bcab55174146aa
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) Test retrieving data from elasticsearch
curl -XGET localhost:9200/test_index/product/1


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) 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


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



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.

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

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