Quantcast
Channel: 钻戒 and 仁豆米
Viewing all articles
Browse latest Browse all 290

Elasticsearch的一个简单查询界面

$
0
0

往elasticsearch里导入数据 里,我们已经弄了很多数据导入了elasticsearch,那么,我们来弄个查询界面吧。

我们要查的对象是collections,查询方式就是最基本的,类似下面

GET /collections/collection/_search?q=*  

套一个angularJS的外壳

源代码下载

解压,把_site目录下的所有东西放到任意一个web目录下. 我们的web服务器ip是172.16.8.1,和elasticsearch不在同一台上。

修改一下js/config.js,改成elasticsearch服务器的地址,index_name和type:

var CALACA_CONFIGS = {  
        url: "http://172.16.11.2:9200",
        index_name: "collections",
        type: "collection",
        size: 10,
        search_delay: 500
}

由于我们的web服务器和elasticsearch不在同一台上,如上做完,在网页中打开index.html,会出来界面,但是查不到任何东西,打开js调试,发现报错:

XMLHttpRequest cannot load http://172.16.11.2:9200/. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://172.16.8.1' is therefore not allowed access.  

貌似是不允许跨站访问,得,修改一下elasticsearch

# vi elasticsearch-2.3.3/config/elasticsearch.yml
...
http.port: 9200  
http.compression: true  
http.max_content_length: 1024mb  
http.cors.enabled : true //  
http.cors.allow-origin: "/.*/"  
http.cors.allow-methods : OPTIONS, HEAD, GET, POST, PUT, DELETE  
http.cors.allow-headers : "X-Requested-With,X-Auth-Token,Content-Type,  Content-Length, Authorization"  
index.store.compress.stored: true  
index.store.compress.tv: true  

如上,增加了http.cors的4行,如果用了jsonp,也可以加这个

http.jsonp.enable: true  

然后在浏览器打开,就ok了。

搜个词:“Aficionado”,马上会出结果


Viewing all articles
Browse latest Browse all 290

Trending Articles