Gitter migration: Setup redirects (rollout pt. 3)
[gitter.git] / server / utils / elasticsearch-typeahead-client.js
blob6bf64a3995859a6ac5277a77e8d7529e916298f5
1 'use strict';
3 var env = require('gitter-web-env');
4 var logger = env.logger;
5 var config = env.config;
6 var elasticsearch = require('elasticsearch');
7 var Promise = require('bluebird');
8 var debug = require('debug')('gitter:infra:elasticsearch');
10 function ElasticSearchLoggingAdapter(/*config*/) {}
12 ElasticSearchLoggingAdapter.prototype.error = function(error) {
13 logger.error('es: error ' + error, { exception: error });
16 ElasticSearchLoggingAdapter.prototype.warning = function(message) {
17 logger.warn('es: ' + message);
20 ElasticSearchLoggingAdapter.prototype.info = function(message) {
21 debug('es: ' + message);
24 ElasticSearchLoggingAdapter.prototype.debug = function(message) {
25 debug(message);
28 ElasticSearchLoggingAdapter.prototype.trace = function(
29 method,
30 requestUrl,
31 body /*, responseBody, responseStatus*/
32 ) {
33 debug('trace: method=%s url=%s, body=%j', method, requestUrl && requestUrl.path, body);
35 ElasticSearchLoggingAdapter.prototype.close = function() {};
37 function defer() {
38 var resolve, reject;
39 var promise = new Promise(function() {
40 resolve = arguments[0];
41 reject = arguments[1];
42 });
43 return {
44 resolve: resolve,
45 reject: reject,
46 promise: promise
50 module.exports = new elasticsearch.Client({
51 hosts: config.get('elasticsearchTypeahead:hosts'),
52 // Warning: possible memory leak: https://github.com/elasticsearch/elasticsearch-js/issues/71
53 sniffOnStart: config.get('elasticsearch:sniffOnStart'),
54 sniffInterval: 300000,
55 apiVersion: '2.3',
56 defer: defer,
57 log: ElasticSearchLoggingAdapter
58 });