added a warning about reusing config objects to the config docs and to the Client constructor

This commit is contained in:
Spencer Alger
2014-03-27 12:54:11 -07:00
parent 0f158381b3
commit db51f0ebaf
2 changed files with 12 additions and 2 deletions

View File

@ -1,16 +1,19 @@
[[configuration]] [[configuration]]
== 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 <<config-options>> section all of the available options/keys are listed.
[source,js] [source,js]
------ ------
var elasticsearch = require('elasticsearch'); var elasticsearch = require('elasticsearch');
var client = new elasticsearch.Client({ 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 === Config options
[horizontal] [horizontal]
`host or hosts`[[config-hosts]]:: `host or hosts`[[config-hosts]]::

View File

@ -32,6 +32,13 @@ var _ = require('./utils');
function Client(config) { function Client(config) {
config = 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() { function EsApiClient() {
// our client will log minimally by default // our client will log minimally by default
if (!config.hasOwnProperty('log')) { if (!config.hasOwnProperty('log')) {