【发布时间】:2017-05-23 08:20:29
【问题描述】:
我想在 Lucene 引擎中查询由 elasticsearch 索引的数据,但我希望通过使用 SSL 来确保此连接的安全:
https://x.y.z.w:9200/index_name/_search?&q=field:value
这是我的全部代码:
<!doctype html>
<html lang="fa">
<head>
<title>XHR App Test</title>
<script>
function send() {
var xhr = new XMLHttpRequest(),
url = 'https://x.y.z.w:9200/index_name/_search?&q=field:value',
sendButton = document.getElementById('sendButton');
xhr.onreadystatechange = function(e) {
console.log(e);
if (e.currentTarget.readyState > 2) {
document.getElementById('result').innerHTML = e.currentTarget.responseText;
}
};
xhr.open('GET', url, true);
xhr.send(null);
}
</script>
</head>
<body>
<h1>XHR App Test</h1>
<button id='sendButton' onclick="send()">Send</button>
<div id="result"></div>
</body>
</html>
我还在elasticsearch.yml 文件中添加了这些配置:
http.port: 9200
http.cors.enabled : true
http.cors.allow-origin: /https?:\/\//
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"
# http.cors.allow-credentials : true
但是只能通过http协议而不是https来查询。
如何解决?
【问题讨论】:
-
您需要使用 Shield 插件设置 SSL/TLS:elastic.co/guide/en/shield/current/ssl-tls.html 或使用 XPack:elastic.co/guide/en/x-pack/current/ssl-tls.html
-
@Val 同意。您可以将您的评论作为答案吗?谢谢! :)
-
@dadoonet 谢谢,完成...新年快乐 ;-)
-
弹性搜索的免费和开源安全github.com/floragunncom/search-guard
标签: rest elasticsearch lucene