Elastic Search : Sample code

Sample code to test elastic search with nodejs module

//Install module elastic search
var elasticsearch = require('elasticsearch');

//Create a new client

var client = new elasticsearch.Client({
  host: 'localhost:9200',
  log: 'trace'

//Try out connection, Start elasticsearch server ..

  // ping usually has a 3000ms timeout
  requestTimeout: 1000
}, function (error) {
  if (error) {
    console.trace('elasticsearch cluster is down!');
  } else {
    console.log('successful connection .');

//Search in elastic

  index: 'twitter',
  type: 'tweet',
  body: {
    query: {
      match: {
        message: 'Elasticsearch'
}).then(function (resp) {
    var hits = resp.hits.hits;
}, function (err) {

Source : https://github.com/elastic/elasticsearch-js


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s