Code Monkey home page Code Monkey logo

elasticsearch-angular-example's Introduction

Angular + Elasticsearch Example

This is an example project designed to show how you can use elasticsearch.js with angular.

Prerequisites

In order to run this example, you will need to have the following installed

  1. elasticsearch
  2. node.js (with npm)

You will also need to configure elasticsearch to accept requests from the browser using CORS. To enable CORS, add the following to elasticsearch's config file. Usually, this file is located near the elasticsearch executable at config/elasticsearch.yml.

http.cors:
  enabled: true
  allow-origin: /https?:\/\/localhost(:[0-9]+)?/

To run the example:

  1. Clone this repo locally (or just download and unzip it)
git clone https://github.com/spenceralger/elasticsearch-angular-example.git
  1. Move into the project
cd elasticsearch-angular-example
  1. Install the node modules
npm install
  1. Open the index.html file in your browser.

  2. Check out the source for index.html to see how it works.

elasticsearch-angular-example's People

Contributors

spenceralger avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

elasticsearch-angular-example's Issues

From POST method to GET method

Hello
I am using elasticsearch module on AngularJs project.
I am trying to use GET method but it works on POST method.
How can I change the method type from post to get.

angular.module('testApp')
  .service('OurService', function ($http, $window, esFactory) {
    function getData() {
      return esFactory({
        host: 'localhost:9200',
        log: 'trace'
      });
    };

    return ({
      getData: getData
    });
  });

angular.module('testApp')
  .controller('MainCtrl', function ($scope, OurService, esFactory) {
    $scope.getCurrencyDataFromCurrencylayer = function() {
      var client = OurService.getData();
      console.log(client);
      client.search().then(function (resp) {
        console.log(resp);
      }, function (err) {
        console.log(err);
      });
     };

      $scope.getCurrencyDataFromCurrencylayer();
  });

Access Control Headers : null with elasticsearch.js latest

I've been trying to set things up using the latest version of elasticsearch.js based off this example.

I can't seem to get anywhere I keep getting:
XMLHttpRequest cannot load http://localhost:9200/. The 'Access-Control-Allow-Origin' header contains the invalid value 'null'. Origin 'http://elasticsearch-angular-example.dev' is therefore not allowed access.

This is how I am calling up the client:

ExampleApp.service('client', function (esFactory) {
      return esFactory({
        host: {
          protocol: 'http',
          host: localhost',
          port: 9200,
          headers: {
            'Accept': 'application/json',
            'Content-Type': 'application/json'
          }
        }
      });
    });

Oddly enough if I drag and drop the index.html it seems not to care. But in every other environment it turns up null.

Cannot connect elasticsearch server because of CORS

Follow your guideline, by adding
http.cors: enabled: true allow-origin: /https?:\/\/localhost(:[0-9]+)?/

(My elasticsearch.yml follow yaml syntax)
screenshot from 2016-04-06 16 52 12

into elasticsearch.yml

by running the index.html I got a error message in Chrome Console

XMLHttpRequest cannot load http://localhost:9200/_cluster/state/cluster_name%2Cnodes%2Cmaster_node%2Cversion. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'null' is therefore not allowed access. The response had HTTP status code 403. XMLHttpRequest cannot load http://localhost:9200/_cluster/state/cluster_name%2Cnodes%2Cmaster_node%2Cversion. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'null' is therefore not allowed access. The response had HTTP status code 403.

Have you got other way to config cors for elasticsearch?.
I am using Ubuntu 14.04 and elastic 2.3.1

screenshot from 2016-04-06 16 48 10

How to load elastic-search-angular using webpack and es6

I m trying to use the elastic-search-angular client in angular app which i m trying to build using webpack with es6.
When i load the elastic-search-angular
import angularElasticsearch from 'elasticsearch-browser';
I get this in npm start

WARNING in ./~/elasticsearch-browser/elasticsearch.js
Critical dependencies:
7:418-425 This seems to be a pre-built javascript file. Though this is possible, it's not recommended. Try to require the original source to get better results.
 @ ./~/elasticsearch-browser/elasticsearch.js 7:418-425

And the browser complains:

Error: [$injector:modulerr] Failed to instantiate module function es() due to:
Error: Looks like you are expecting the previous "elasticsearch" module. It is now the "es" module. To create a client with this module use `new es.Client(params)`.

search suggesters completion

How do you use the angular service to do a suggest and pass in the data like below:

curl -X POST 'localhost:9200/music/_suggest?pretty' -d '{
"song-suggest" : {
"text" : "n",
"completion" : {
"field" : "suggest"
}
}
}'

Is there a place where once can see all the possible ways of using the Angular Service?

I can get it to work in 'Sense' following the documentation below:
https://www.elastic.co/guide/en/elasticsearch/reference/current/search-suggesters-completion.html

Thanks

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.