elasticsearch-head安装

elasticsearch-head第三方的查询工具
elasticsearch-head gitcss

环境:
elasticsearch6.xhtml

docker安装:

查询镜像:git

$ docker search elasticsearch-head
INDEX       NAME                                                         DESCRIPTION                                     STARS     OFFICIAL   AUTOMATED
docker.io   docker.io/mobz/elasticsearch-head                            elasticsearch-head front-end and standalon...   46                   
docker.io   docker.io/alivv/elasticsearch-head                           elasticsearch-head front-end and standalon...   6                    
docker.io   docker.io/jeanberu/elasticsearch-head                        ElasticSearch:1 with elasticsearch-head pl...   6                    [OK]
...

拉取镜像:github

$ docker pull docker.io/mobz/elasticsearch-head:5    
....

elasticsearch-head:5 标准版本(最新),兼容elasticsearch 5.x和6.x版本服务正则表达式

运行:chrome

$ docker run -d --name elastic-head -p 9100:9100 mobz/elasticsearch-head:5

访问地址:http:ip:9100docker


QA:

1、没法链接

缘由:默认elasticsearch不支持跨域请求
解决办法:json

http.cors.enabled 是否支持跨域,默认为false
http.cors.allow-origin 当设置容许跨域,默认为*,表示支持全部域名,若是咱们只是容许某些网站能访问,那么能够使用正则表达式。好比只容许本地地址。 /https?://localhost(:[0-9]+)?/

config/elasticsearch.yml文件末尾添加如上两个配置,并重启:跨域

$ tail -n 2 config/elasticsearch.yml 
http.cors.enabled: true
http.cors.allow-origin: "*"


2、正常链接elasticsearch后,没法查询数据

缘由:elasticsearch-head是第三方客户端,默认的contentType:application/x-www-form-urlencoded标头不符合ES6.x新增的安全机制。新版本进行严格的内容类型检查,防止跨站点请求伪造攻击。
解决办法:修改elasicsearch-head程序中的有关 contentType的设置,设置成符合安全机制的contentType:application/json;charset=UTF-8浏览器

$ docker exec  -it elastic-head bash
root@26a619845111:/usr/src/app# cd _site/
root@26a619845111:/usr/src/app/_site# ls -l
total 780
-rw-r--r-- 1 root root  14908 Feb 22  2016 app.css
-rw-r--r-- 1 root root 143298 Jan  6  2017 app.js
drwxr-xr-x 2 root root     61 Nov  3  2015 base
drwxr-xr-x 2 root root    154 Nov  3  2015 fonts
-rw-r--r-- 1 root root   2860 Jun 28  2016 i18n.js
-rw-r--r-- 1 root root   1043 Jan  6  2017 index.html
drwxr-xr-x 2 root root    111 Jan  6  2017 lang
-rw-r--r-- 1 root root  21643 Feb 22  2016 vendor.css
-rw-r--r-- 1 root root 605341 Jun 21 01:58 vendor.js

#修改vendor.js的第6886和7574行,将application/x-www-form-urlencoded改成application/json;charset=UTF-8

修改好的vendor.js文件:https://blog-static.cnblogs.com/files/dance-walter/vendor.js

从新启动服务:

$ docker kill elastic-head
$ docker rm elastic-head
$ mkdir -p /usr/src/app/_site/ #新建目录,并将vendor.js文件上传。docker启动时映射此文件便可
$ docer run -d --name elastic-head -p 9100:9100 -v /usr/src/app/_site/vendor.js:/usr/src/app/_site/vendor.js mobz/elasticsearch-head:5

正常查询:


官网解释:https://www.elastic.co/cn/blog/strict-content-type-checking-for-elasticsearch-rest-requests

最后:
chrome浏览器里的elasticsearch-head插件是没有上述问题的。直接安装便可用。

相关文章
相关标签/搜索