解决ElasticSearch Java High RESTfu

2021-05-10  本文已影响0人  i_cyy

背景:Elasticsearch 7.9.0 开启了用户名密码校验,需要使用用户名密码登入。并且设置的user、role等权限。那么之前直接访问的方式是不行的。需要使用认证的方式进行访问。直接上最终能成功的Clientnt代码:

image.png

最关键的是builder.setDefaulHeaders(new BasicHeader[]{ new BasicHeader("Authorization","Basic "+auth) })
这行代码,需要设置一下请求header,不然会报错:
{ "error": { "root_cause": [ { "type": "security_exception", "reason": "missing authentication credentials for REST request [/bank/_search]", "header": { "WWW-Authenticate": "Basic realm=\"security\" charset=\"UTF-8\"" } } ], "type": "security_exception", "reason": "missing authentication credentials for REST request [/bank/_search]", "header": { "WWW-Authenticate": "Basic realm=\"security\" charset=\"UTF-8\"" } }, "status": 401 }

上一篇下一篇

猜你喜欢

热点阅读