ElasticSearch无法使用相同的来源 [英] ElasticSearch not working with same origin

查看:63
本文介绍了ElasticSearch无法使用相同的来源的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在Ubuntu服务器上安装了ElasticSearch,当我执行cURL命令时,它似乎可以正常工作.但是,当我通过Ajax使用ElasticSearch URI时,出现以下错误: net :: ERR_BLOCKED_BY_CLIENT 这是我的Ajax请求的样子:

I installed ElasticSearch on my Ubuntu server and it seems to be working correctly when I do the cURL command. However, when I use the ElasticSearch URI using Ajax I get the following error: net::ERR_BLOCKED_BY_CLIENT Here's how my Ajax request looks like:

const QUERY_URL = "http://localhost:9200/topics/_search?q=name:" + QUERY
    + "*&sort=follower_count:desc&size=5";

$.ajax({
    type: 'GET',
    url: QUERY_URL,
    success: function (data) {
        console.log(data);
    },
    error: function (xhr) {
        if (xhr.status === 0) {
            showSnackBarMessage("Can't communicate with server");
        }
    }
});

我尝试使用 POST 而不是 GET .我还尝试将localhost更改为其等效的I.P.但是,似乎没有任何作用.我不断遇到同样的错误.有没有一种方法可以解决这个问题,而无需向世界开放我的ElasticSearch API?

I tried using POST instead of GET. I also tried changing localhost to its I.P equivalent. However, nothing seems to be working. I keep on getting the same error. Is there a way to solve this without opening my ElasticSearch API to the world?

推荐答案

提示:出于安全考虑,切勿直接将弹性橡胶暴露在互联网上!

该错误出在客户端(您的浏览器/您的代码)中,因为CORS设置阻止您从网站以外的其他主机调用资源(端口可能不同,对吗?).例如,您的网站在localhost:8080上运行,并且您需要ajax localhost:9200将引导到 net :: ERR_BLOCKED_BY_CLIENT

The error is in the client (your browser/your code) because the CORS settings prevents you to call resources from another host than your website (the port might be different, right?). For Example, your website is running at localhost:8080 and you need to ajax localhost:9200 will lead into net::ERR_BLOCKED_BY_CLIENT

您需要处理CORS正确地在您的客户端/jquery中,并且可以在 elasticsearch HTTP网络

这篇关于ElasticSearch无法使用相同的来源的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆