角度和弹性搜索的例子 [英] Example of Angular and Elasticsearch

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

问题描述

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



到目前为止,我发现的示例使用备用客户端或不再工作,因为版本之间有变化。这使得AngularJS和Elasticsearch的新用户很难开始使用。



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



其他似乎有同样的问题,因为在官方客户的回购中要求同样的事情是一个公开的问题。
https://github.com/elasticsearch/elasticsearch-js/issues/19

这是一个结合AngularJS和Elasticsearch

$ b做一个Hello World的方法
$ b

1)确保您已在本地计算机上正确安装弹性搜索
说明



2)测试本地安装弹性搜索

通过键入命令行

curl -XGET localhost:9200



3)将一些测试数据插入弹性搜索

只需运行这个 gist (点击每个旁边的小绿色三角形)
或者你可以插入通过在命令行中键入以下命令手动输入ert数据:

  curl -XPUThttp:// localhost:9200 / test_index /产品/ 1-d{
title:Product1,
description:Product1 Description,
price:100
}'

curl -XPUThttp:// localhost:9200 / test_index / product / 2-d'{
title:Product2,
description:Product2说明,
price:200
}'

4) strong>测试从elasticsearch检索数据

curl -XGET localhost:9200 / test_index / product / 1



5)下载 angular.elasticsearch.js (或最小化版本)客户端,并将其放置在可用的位置Angular应用程序(同一目录应该是好的)



6)下载并运行e以下代码

http://plnkr.co/edit/vfapGG


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



恭喜!!

您现在有一个工作弹性搜索后端和AngularJS前端。



警告

在开始生产之前,请务必妥善保护您的Elasticsearch服务器,任何人都可以轻松地修改或删除您存储的数据并获得CONTROL (基本上是shell访问)运行Elasticsearch服务器的计算机,如果它没有得到正确的保护。


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

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

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

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