1。elasticsearch.yml
#跨域开启,允许所有的地址访问
http.cors.enabled: true
http.cors.allow-origin: "*"
http.cors.allow-headers: Authorization,Content-Type,X-Requested-with,Content-Length
xpack.security.enabled: true
xpack.security.transport.ssl.enabled: true
xpack.ml.enabled: true
2.elasticsearch-7.6.1.1\bin 打开cmd窗口
1.先开启 elasticsearch.bat
2. 在cmd窗口输入:elasticsearch-setup-passwords interactive
输入y,再输入 密码:zhangqiang ,然后重启
3.之前访问: http://localhost:9200/
4.添加密码之后 直接输入 http://localhost:9200/ 不能访问
需要输入:http://localhost:9200/?auth_user=elastic&auth_password=zhangqiang才能访问
5.在更高版本中可能会出现还是不能访问的问题:
可做适当的修改:
httpcors.allow-origin: "/.*/"
htto cors allow-headers: WWW-Authenticate,X-Requested-With X-Auth-Token Content-Type.Content-Length Authorization
1.可将index.html中的 auth_user:与auth_password直接写上去:
2.如上修改会出现如下错误访问不了其中的特定post接口:
可做如下修改:
head安装目录_site/vendor.js的6886,7573行附近修改,"applicatlon/x-www-form-urlencoded"改为:"application/son; charset-uTF-8”
重新访问即可(结束)
附录:如不想修改index.html中的用户名密码也可以修改
_site/app.js 中的代码,将4334行中的if判断去掉 ,然后使用java代码对 ES的用户名密码进行base64进行编码:如 用户名密码为: elastic abcde123
则使用java进行base64编码: Base64.encode(elastic:abcde123)
将编码后得放到4338行:credentials中 直接写死即可。