预检请求错误:Elastic Search

时间:2016-03-25 11:08:29

标签: angularjs elasticsearch

我想从Angular JS调用弹性搜索Web服务。当我打电话给它时如下:

$http.post('http://[IP]:9200/providers3/provider3/_search',JSON.stringify(objToSend)).success(function(){

            console.log('Data sent successfully!!');

        });

我收到此错误:

XMLHttpRequest cannot load http://[IP]:9200/providers3/provider3/_search. Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin "http://localhost:8085" is therefore not allowed access.

我在elasticsearch.yml文件中进行了如下更改:

http.cors.enabled : true // 
http.cors.allow-origin: "/.*/"
http.cors.allow-methods : OPTIONS, HEAD, GET, POST, PUT, DELETE
http.cors.allow-headers : "X-Requested-With,X-Auth-Token,Content-Type, Content-Length, Authorization"*

但是在将这些行添加到.yml文件后,弹性搜索服务器无法启动。

请有人帮忙吗?

1 个答案:

答案 0 :(得分:0)

如果您将allow-origin更改为“*”而不是当前正则表达式,该怎么办?它应该工作,我有同样的问题。