Cannot access elastic search using elasticsearch.angular in my angular App

100 views
Skip to first unread message

Sajeetharan Sinnathurai

unread,
Feb 19, 2015, 12:59:38 AM2/19/15
to ang...@googlegroups.com

I can access the data when i just put the requet in browser http://localhost:9222/_cat/indices?0=b

But in my angular app this does not work returning an error saying,

XMLHttpRequest cannot load http://localhost:9222/_cat/indices?0=b. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost' is therefore not allowed access.

Here is the code,

// Create the es service from the esFactory routerApp.service('es', function (esFactory) { return esFactory({ host: 'localhost:9222' }); });

routerA

pp
.controller("elasticController",function($scope,es){ $scope.indexes = []; es.cat.indices("b",function(r,q){ var re = /open +(.+?) +1/g; matches = []; while (match = re.exec(q)) matches.push(match[1]); for (var i = 0; i < matches.length; i++) { var indObj = {id:i, index:matches[i]}; $scope.indexes.push(indObj); }; });

I have added the config in the elasticsearch.yml on elastic server.

http.cors.allow-origin: "/.*/"

Justin Walsh

unread,
Feb 26, 2015, 1:45:18 PM2/26/15
to ang...@googlegroups.com
Hi, 

The fact that you are able to open the 'offending' URL directly in your browser is not surprising.  There is no resource sharing since there is a single origin (the URL you opened).

Angular's access to the resource is blocked because in that case you have 2 origins
  1. The URL of the angular app which you are running
  2. The elastic search URL from which you are fetching data
My guess is that your CORS configuration is not set up correctly (which you have probably figured this out by now...)

Regards
Justin
Reply all
Reply to author
Forward
0 new messages