ElasticSearch:jquery ajax http 请求中需要用户身份验证
ElasticSearch: user authentication required in jquery ajax http request
我正在使用部署在 Google 云上的 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
文件,但是当我单击 save
按钮时它给我一个错误 'xpack.security.enabled': is not allowed
。
如何禁用用户身份验证要求或如何在我的 HTTP 请求中通知 user/password?
我会通过在 headers
散列中添加身份验证来做到这一点:
$.ajax({
method: "GET",
url: "https://6ce.......5d14.us-west1.gcp.cloud.es.io:9243/itens/_search",
dataType : 'json',
contentType: 'application/json',
--> headers: {
--> "Authorization": "Basic " + btoa("elastic:XXX_PASSWORD_XXX")
--> }
})
我正在使用部署在 Google 云上的 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
文件,但是当我单击 save
按钮时它给我一个错误 'xpack.security.enabled': is not allowed
。
如何禁用用户身份验证要求或如何在我的 HTTP 请求中通知 user/password?
我会通过在 headers
散列中添加身份验证来做到这一点:
$.ajax({
method: "GET",
url: "https://6ce.......5d14.us-west1.gcp.cloud.es.io:9243/itens/_search",
dataType : 'json',
contentType: 'application/json',
--> headers: {
--> "Authorization": "Basic " + btoa("elastic:XXX_PASSWORD_XXX")
--> }
})