Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

replace elasticsearch.angular.js with plain $http? #2

Closed
xat opened this issue Jul 9, 2014 · 5 comments
Closed

replace elasticsearch.angular.js with plain $http? #2

xat opened this issue Jul 9, 2014 · 5 comments

Comments

@xat
Copy link

xat commented Jul 9, 2014

It seems that elasticsearch.angular.js is only used to send Ajax Requests, which could also easily be done by using plain $http. Since this dependency has a size of a few hundred KB I ask myself if there is another benefit that I'm not aware of?

@psi-4ward
Copy link

angular.module('elasticsearch', [])
.factory('esFactory', ['$http', '$q', function($http, $q) {
    return function(clientOpts) {
      return {
        search: function(searchOpts) {
          var defer = $q.defer();
          $http({
            method: 'POST',
            url: clientOpts.host + searchOpts.index + '/_search',
            params: {
              size: searchOpts.size,
              from: searchOpts.from
            },
            data: searchOpts.body.toJSON()
          }).then(
            function(body) {
              defer.resolve(body.data);
            },
            function() {
              defer.reject.apply(this, arguments);
            }
          );
          return defer.promise;
        }
      };
    };
  }]);

@xat
Copy link
Author

xat commented Jul 9, 2014

+1

@YousefED
Copy link
Owner

Seems like a good idea indeed. Could you confirm the code by @psi-4ward works well with ElasticUI?

@xat
Copy link
Author

xat commented Jul 14, 2014

@YousefED The Code worked in my case.

@YousefED
Copy link
Owner

I've moved this to a separate repository: https://github.com/YousefED/elasticsearch.angular.simple/, hope you don't mind :)

I think it's a great addition but doesn't directly belong in ElasticUI

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants