<commit_before>
var elasticsearch = require('elasticsearch'),
    defaults = require('../config/defaults'),
    BufferedBulkStream = require('./BufferedBulkStream')
    livestats = require('./livestats');

module.exports = function(){

  var copyDefaults = {};
  for( var attr in defaults ){
    copyDefaults[ attr ] = defaults[ attr ];
  }

  // Create new esclient with default settings
  var client = new elasticsearch.Client( copyDefaults );

  // Provide a simple utility to convert client errors to standard nodejs interface (err,res)
  // @deprecated?
  client.errorHandler = function(cb) {
    return function(err, data, errcode) {
      if(err && err.message) {
        return cb(err.message, data);
      }
      return cb(null, data);
    }
  }

  // Create a streaming interface to the bulk API with buffering enabled
  client.stream = new BufferedBulkStream( client );
  client.livestats = livestats.bind( null, client.stream );

  return client;

}<commit_msg>allow config to be injected<commit_after>
var elasticsearch = require('elasticsearch'),
    defaults = require('../config/defaults'),
    BufferedBulkStream = require('./BufferedBulkStream')
    livestats = require('./livestats');

module.exports = function( config ){

  var copyDefaults = {};
  for( var attr in defaults ){
    copyDefaults[ attr ] = defaults[ attr ];
  }

  // Create new esclient with default settings
  var client = new elasticsearch.Client( copyDefaults );

  // Provide a simple utility to convert client errors to standard nodejs interface (err,res)
  // @deprecated?
  client.errorHandler = function(cb) {
    return function(err, data, errcode) {
      if(err && err.message) {
        return cb(err.message, data);
      }
      return cb(null, data);
    }
  }

  // Create a streaming interface to the bulk API with buffering enabled
  client.stream = new BufferedBulkStream( client, config );
  client.livestats = livestats.bind( null, client.stream );

  return client;

}
{'fraction_non_alphanumeric': 0.11577350859453994, 'fraction_numerical': 0.0, 'mean_word_length': 3.397777777777778, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '709436', 'n_tokens_mistral': 566, 'n_tokens_neox': 551, 'n_words': 172}