rufuspollock-okfn / elasticsearch.js

A simple javascript library for working with ElasticSearch
78 stars 18 forks source link

Undefined value returning var table = ES.Table(endpoint); #14

Open KrishnaPG opened 9 years ago

KrishnaPG commented 9 years ago

Hello,

Trying to follow your example, but getting 'undefined value' error from ES.Table() function. You can try the below sample code and put a break point nere the 'problem here' statement and verify the problem.

<!DOCTYPE html>

<html lang="en">
    <head>
        <meta charset="utf-8" />
        <title></title>
        <!-- Bootstrap  CSS -->
        <link rel="stylesheet" href="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.1/css/bootstrap.min.css">
        <link rel="stylesheet" href="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.1/css/bootstrap-theme.min.css">
        <link rel="stylesheet" href="http://cdn.datatables.net/1.10.4/css/jquery.dataTables.min.css">

    </head>
    <body>
        <h1>Hello World !!</h1>
        <div class="col-md-12">
            <table cellpadding="0" cellspacing="0" border="0" class="display" id="mygrid"></table>
        </div>

        <script type="text/javascript" src="http://cdnjs.cloudflare.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> 
        <script type="text/javascript" src="http://cdnjs.cloudflare.com/ajax/libs/underscore.js/1.7.0/underscore-min.js"></script>
        <script type="text/javascript" src="http://cdnjs.cloudflare.com/ajax/libs/backbone.js/1.1.2/backbone-min.js"></script>
        <script type="text/javascript" src="http://cdnjs.cloudflare.com/ajax/libs/mustache.js/0.8.1/mustache.min.js"></script>   
        <script type="text/javascript" src="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.1/js/bootstrap.min.js"></script>
        <script type="text/javascript" src="http://cdn.datatables.net/1.10.4/js/jquery.dataTables.js"></script> <!--jquery.dataTables.min.js-->
        <script type="text/javascript" src="http://okfnlabs.org/elasticsearch.js/elasticsearch.js"></script>

        <script type="text/javascript">     
    var endpoint = 'http://192.168.56.106:9200/tweets/tweet';

    var table = ES.Table(endpoint); // <-- PROBLEM HERE
        </script>
    </body>
</html>
ghost commented 8 years ago

Hi, was there an answer to this question? I'm getting the same error. Thanks.

rufuspollock commented 8 years ago

@ram-bcll-tech to patch we'd really want a failing test. Is there any way to see if you can get that?

ghost commented 8 years ago

Thank you for your response. I'm new to ES and was trying to follow your tutorial. This may very well be a simple usage issue.

I do have the ES running on a server and I'm able to successfully query and get responses from the server on clients via HTTP.. However, when I try to embed the query in an app in a browser (Chrome Version 53.0.2785.143 (64-bit)), the code (attached) doesn't seem to go past the line, "var elasticsearch = require('elasticsearch');". I placed simple console.log messages immediately before and after this line. I see the preceding comment printed in the console, but, not the following one and there are no other messages, error or otherwise, in the console, so, I'm not able to figure out what the issue is. Thanks for any help you can provide.

App.prototype.getMinorsCount = function() { console.log("starting elasticsearch connection"); var elasticsearch = require('elasticsearch'); console.log("past elasticsearch declaration");

var client = new elasticsearch.Client({
  host: 'http://<server_name>.amazonaws.com:9200',
  log: 'trace'
});

client.ping({

requestTimeout: 30000,

  // undocumented params are appended to the query string
  hello: "elasticsearch"
}, function (error) {
  if (error) {
    console.error('elasticsearch cluster is down!');
  } else {
    console.log('All is well');
  }
});

};

console output:

starting elasticsearch connection

rufuspollock commented 8 years ago

@ram-bcll-tech got you. The thing is without some error output it is tough to debug. Do you see any error messages in the console?

ghost commented 8 years ago

Sorry, i thought I had responded to your last note, but, i don't see it online.

To answer your last question, no, I don't see any error messages. This is what has me stumped as well.

ghost commented 8 years ago

No, unfortunately the only message in the console is the console.log message, immediately preceding "var elasticsearch = require('elasticsearch');" line. The console.log message immediately following the var line is not executed. I do know that nothing else in the function gets executed either as there are other console.log messages in the function that are not executed.

Thanks for your help.

Best regards, Ram

Here's the entire function (stripped down for simplicity):

PTApp.prototype.getMinorsCount = function() { console.log("starting elasticsearch connection"); <== this is printed var elasticsearch = require('elasticsearch'); console.log("past elasticsearch declaration"); <== this is NOT printed

var client = new elasticsearch.Client({
  host: 'http://ec2-54-166-167-126.compute-1.amazonaws.com:9200',
  log: 'trace'
});

client.ping({
  requestTimeout: 30000,
  hello: 'elasticsearch'
}, function (error) {
  if (error) {
    console.error('elasticsearch cluster is down!');
  } else {
    console.log('All is well');
  }
});

console.log("leaving elasticsearch connection"); };

On Thu, Oct 20, 2016 at 8:56 AM, Rufus Pollock notifications@github.com wrote:

@ram-bcll-tech https://github.com/ram-bcll-tech got you. The thing is without some error output it is tough to debug. Do you see any error messages in the console?

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/okfn/elasticsearch.js/issues/14#issuecomment-255097846, or mute the thread https://github.com/notifications/unsubscribe-auth/ARrhNAYfuB2w0iBmrIKVdLDsg73IK1JXks5q12T0gaJpZM4DKW-n .