【发布时间】:2015-01-04 02:00:50
【问题描述】:
我有一个 javascript 演示客户端,它尝试在 Elasticsearch 上进行搜索,该搜索在 Amazon AWS Cloud 上运行良好。
事情是我得到了结果(提琴手显示它在 JSON 中很好,应该是这样)。但是浏览器用这个来打击我:
XMLHttpRequest cannot load http://ec2-xx-xxx-xxx-xxx.us-west-2.compute.amazonaws.com:9200/pekara/hljeb/_search. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost:7000' is therefore not allowed access.
这是我使用的演示 Ajax:
var searchString = "http://ec2-xx-xxx-xxx-xxx.us-west-2.compute.amazonaws.com:9200/pekara/hljeb/_search";
debugger;
$.ajax({
url: searchString,
type: 'POST',
contentType: 'application/json; charset=UTF-8',
dataType: "json",
crossDomain: true,
data: JSON.stringify(data),
success: function (data) {
console.log("And this is success: " + data);
$("#contentholder").text(data);
}
}).fail(function (error) {
console.log("Search Failed")
})
}
重复一遍,Fiddler 显示结果返回,但浏览器每次都指向失败方法。 本例中如何解析 CORS?
演示应用程序正在 Node.js 上作为服务器。
这是我的 elasticsearch.yaml 文件的内容:
文件的其余部分是默认的,这意味着所有内容都被注释掉了:
{
"cluster.name": "Mycluster",
"node.name": "My-node",
"cloud": {
"aws": {
"access_key": "xxxxxxxxxxxxxxxxxxxxxx",
"secret_key": "xxxxxxxxxxxxxxxxx"
}
},
"discovery": {
"type": "ec2",
"ec2" : {
"groups": "Elastic-Search-GROUP"
}
}
}
http.cors.allow-origin: true,
http.cors.allow-methods: true,
http.cors.allow-headers: true,
http.cors.allow-credentials: true,
http.cors.enabled: true
【问题讨论】:
标签: amazon-web-services elasticsearch cors