From db51f0ebafa5ec124df8de60879bf3ff70984e6e Mon Sep 17 00:00:00 2001 From: Spencer Alger Date: Thu, 27 Mar 2014 12:54:11 -0700 Subject: [PATCH] added a warning about reusing config objects to the config docs and to the Client constructor --- docs/configuration.asciidoc | 7 +++++-- src/lib/client.js | 7 +++++++ 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/docs/configuration.asciidoc b/docs/configuration.asciidoc index 462986535..f561b9b68 100644 --- a/docs/configuration.asciidoc +++ b/docs/configuration.asciidoc @@ -1,16 +1,19 @@ [[configuration]] == Configuration -The `Client` constructor accepts a single object as it's argument, and the following keys can be used to configure that client instance. +The `Client` constructor accepts a single object as it's argument. In the <> section all of the available options/keys are listed. [source,js] ------ var elasticsearch = require('elasticsearch'); var client = new elasticsearch.Client({ - ... + ... config options ... }); ------ +WARNING: Due to the complex nature of the configuration, the config object you pass in will be modified and can only be used to create one `Client` instance. Sorry for the inconvenience. Related Github issue: https://github.com/elasticsearch/elasticsearch-js/issues/33 + +[[config-options]] === Config options [horizontal] `host or hosts`[[config-hosts]]:: diff --git a/src/lib/client.js b/src/lib/client.js index fb677e19a..ff7d612ea 100755 --- a/src/lib/client.js +++ b/src/lib/client.js @@ -32,6 +32,13 @@ var _ = require('./utils'); function Client(config) { config = config || {}; + if (config.__reused) { + throw new Error('Do not reuse objects to configure the elasticsearch Client class: ' + + 'https://github.com/elasticsearch/elasticsearch-js/issues/33'); + } else { + config.__reused = true; + } + function EsApiClient() { // our client will log minimally by default if (!config.hasOwnProperty('log')) {