我正在使用部署在 Google Cloud 上的 ElasticSearch 14 天试用服务,并尝试从 JQuery 发出 HTTP 请求以在 ElasticSearch 上实现通用搜索。
$.ajax({
method: "GET",
url: "https://6ce.......5d14.us-west1.gcp.cloud.es.io:9243/itens/_search",
dataType : 'json',
contentType: 'application/json',
})
.done(function( data ) {
console.log(data);
})
.fail(function( data ) {
console.log(data);
});
但这给了我一个错误的401-Unauthorized
说法:
responseText: "{\"error\":{\"root_cause\":[{\"type\":\"security_exception\",\"reason\":\"action [indices:data/read/search] requires authentication\",\"header\":{\"WWW-Authenticate\":[\"Bearer realm=\\\"security\\\"\",\"ApiKey\",\"Basic realm=\\\"security\\\" charset=\\\"UTF-8\\\"\"]}}],\"type\":\"security_exception\",\"reason\":\"action [indices:data/read/search] requires authentication\",\"header\":{\"WWW-Authenticate\":[\"Bearer realm=\\\"security\\\"\",\"ApiKey\",\"Basic realm=\\\"security\\\" charset=\\\"UTF-8\\\"\"]}},\"status\":401}"
我elasticsearch.yml
将文件编辑为:
http.cors.enabled: true
http.cors.allow-origin: "*"
http.cors.allow-methods: OPTIONS, HEAD, GET, POST, PUT, DELETE
http.cors.allow-headers: "Authorization, X-Requested-With, X-Auth-Token, Content-Type, Content-Length"
http.cors.allow-credentials: true
然后我重新启动了部署,但它仍然无法正常工作。
我也尝试添加xpack.security.enabled: false
到文件,但是当我单击按钮时elasticsearch.yml
它给了我一个错误。'xpack.security.enabled': is not allowed
save
如何禁用用户身份验证要求或如何在我的 HTTP 请求中通知用户/密码?