ncb000gt / node-es

NodeJS module for ElasticSearch.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Setting options dynamically

omundy opened this issue · comments

This example from the README which sets the index dynamically does not appear to work. It always returns undefined. Am I doing something wrong? See comments...

var hapi = require('hapi');
var server = new hapi.Server();

var elasticsearch = require('es'),
    config = {
      _index : 'dogs',
      _type : 'dog'
    },
    es = elasticsearch(config);


server.connection({ port: 3300, host: 'localhost' });

server.route({
    method: 'GET',
    path: '/',
    handler: function (request, reply) {

        // this works
        es.count(function (err, data) {
            console.log(data);
        });

        // setting options dynamically does not
        var options = {
            _index : 'cats',
            _type : 'cat'
        }
        es.count(options, function (err, data) {
            console.log(data);
        });

    }
});

server.start(function (err) {
    if (err) {
        throw err;
    }
  console.log('hapi server started');
});

@omundy - my apologies for the long delay on a fix... this is now repaired in v0.5.2