Amazon AWS Cloud에서 행복하게 실행되는 Elasticsearch에서 검색을 시도하는 javascript의 데모 클라이언트가 있습니다.AWS에서 AJAX를 elasticsearch로 만들 때 CORS 문제가 발생합니다.
결과는 내가 결과를 다시 얻는다는 것입니다 (피들러는 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.
이 내가 사용하는 데모 아약스입니다 :
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")
})
}
그래서 반복, 피들러는 결과가 돌아 오면 보여 주지만, 브라우저 점은 모든 방법을 실패 한 번. 이 예에서 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
그래서 이러한 속성을 elasticsearch.yaml 파일에 추가합니까? –
예, 좋을 것입니다. –
우리가 말한대로 그것을 시도 :). 결과 게시 즉시 –