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: "/.*/"