0

我正在使用部署在 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 allowedsave

如何禁用用户身份验证要求或如何在我的 HTTP 请求中通知用户/密码?

4

1 回答 1

2

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")
    -->   }
        })
于 2019-08-28T06:22:16.537 回答