Files
elasticsearch-js/docs/host.asciidoc
2015-01-06 07:55:56 -07:00

145 lines
3.9 KiB
Plaintext

[[host-reference]]
== Host
The host class is used to represent a single node/host/endpoint. These objects are created automatically by the Client constructor, as well as during sniff operations.
=== Constructor(params)
==== Params
Params can either be URL string, or an object with the following properties
[horizontal]
`host`::
`String` -- The name of the host
Default ::: `"localhost"`
`port`::
`Number` -- The port number to use for this host
Default ::: `9200`
`protocol`::
`String` -- The name of the protocol this host is reachable on
Default ::: `"http"`
Options :::
* `"http"`
* `"https"`
`path`::
`String` -- A path prefix that should be prepended to every path requested.
`auth`::
`String` -- Basic authentication i.e. 'user:password' to compute an Authorization header.
`query`::
`String,Object` -- A default set of query string parameters to use on every request.
`headers`::
`Object` -- An object describing the headers to send for every request to this node.
`...`::
`Any` -- When the host receives a configuration object, it assigns all of the object's keys to itself. This allows you to pass in arbitrary keys and values that can be used within selectors, or other custom functionality.
`ssl`::
`Object` -- configuration options pertaining to HTTPS/SSL. For more information visit the <<auth-reference>> Section.
`ssl.pfx`::
`String,Array[String]` -- Certificate, Private key and CA certificates to use for SSL.
Default ::: `null`
`ssl.key`::
`String` -- Private key to use for SSL.
Default ::: `null`
`ssl.passphrase`::
`String` -- A string of passphrase for the private key or pfx.
Default ::: `null`
`ssl.cert`::
`String` -- Public x509 certificate to use.
Default ::: `null`
`ssl.ca`::
`String,Array[String]` -- An authority certificate or array of authority certificates to check the remote host against.
Default ::: `null`
`ssl.ciphers`::
`String` -- A string describing the ciphers to use or exclude. Consult http://www.openssl.org/docs/apps/ciphers.html#CIPHER_LIST_FORMAT for details on the format.
Default ::: `null`
`ssl.rejectUnauthorized`::
`Boolean` -- If true, the server certificate is verified against the list of supplied CAs. An 'error' event is emitted if verification fails. Verification happens at the connection level, before the HTTP request is sent.
Default ::: `false`
`ssl.secureProtocol`::
`String` -- The SSL method to use, e.g. TLSv1_method to force TLS version 1. The possible values depend on your installation of OpenSSL and are defined in the constant SSL_METHODS.
Default ::: `null`
=== Examples
.Using your application to proxy/filter elasticsearch requests can sometimes be a good idea. Use this configuration to always send requests to `https://my-site.com/elasticsearch/{{request url}}` rather than directly to elasticsearch.
[source,js]
-----
var client = new elasticsearch.Client({
host: {
protocol: 'https',
host: 'my-site.com',
port: 80,
path: '/elasticsearch/'
}
})
-----
.Use custom keys/vals to add special properties to the hosts, that are used by the selector.
[source,js]
-----
var client = new elasticsearch.Client({
hosts: [
{
protocol: 'https',
host: 'box1.server.org',
port: 56394,
// these custom values are used below by the selector
country: 'EU',
weight: 10
},
{
protocol: 'https',
host: 'box2.server.org',
port: 56394,
// these custom values are used below by the selector
country: 'US',
weight: 50
}
],
selector: function (hosts) {
var myCountry = process.env.COUNTRY;
// first try to find a node that is in the same country
var selection = _.find(nodes, function (node) {
return node.host.country === myCountry;
});
if (!selection) {
// choose the node with the lightest weight.
selection = _(nodes).sortBy(function (node) {
return node.host.weight;
}).first();
}
return selection;
}
});
-----