2016-04-03 22:09:24 +08:00
[[settings]]
2021-04-29 09:30:32 +08:00
== Configuring {es}
2014-06-12 19:56:06 +08:00
2021-04-29 09:30:32 +08:00
{es} ships with good defaults and requires very little configuration.
2016-04-03 22:09:24 +08:00
Most settings can be changed on a running cluster using the
<<cluster-update-settings>> API.
2013-10-17 17:54:36 +08:00
2016-04-03 22:09:24 +08:00
The configuration files should contain settings which are node-specific (such
as `node.name` and paths), or settings which a node requires in order to be
able to join a cluster, such as `cluster.name` and `network.host`.
2014-11-22 04:41:06 +08:00
2017-08-01 08:52:23 +08:00
[[config-files-location]]
2020-07-23 23:48:22 +08:00
[discrete]
2017-08-01 08:52:23 +08:00
=== Config files location
2014-05-02 16:44:26 +08:00
2021-04-29 09:30:32 +08:00
{es} has three configuration files:
2014-05-14 22:01:25 +08:00
2021-04-29 09:30:32 +08:00
* `elasticsearch.yml` for configuring {es}
* `jvm.options` for configuring {es} JVM settings
* `log4j2.properties` for configuring {es} logging
2014-05-14 22:01:25 +08:00
2017-08-01 08:52:23 +08:00
These files are located in the config directory, whose default location depends
on whether or not the installation is from an archive distribution (`tar.gz` or
`zip`) or a package distribution (Debian or RPM packages).
2014-05-14 22:01:25 +08:00
2017-08-01 08:52:23 +08:00
For the archive distributions, the config directory location defaults to
`$ES_HOME/config`. The location of the config directory can be changed via the
2017-08-15 05:19:06 +08:00
`ES_PATH_CONF` environment variable as follows:
2014-05-14 22:01:25 +08:00
[source,sh]
2016-04-03 22:09:24 +08:00
-------------------------------
2017-08-15 05:19:06 +08:00
ES_PATH_CONF=/path/to/my/config ./bin/elasticsearch
2016-04-03 22:09:24 +08:00
-------------------------------
2013-08-29 07:24:34 +08:00
2017-08-15 05:19:06 +08:00
Alternatively, you can `export` the `ES_PATH_CONF` environment variable via the
2017-08-01 08:52:23 +08:00
command line or via your shell profile.
For the package distributions, the config directory location defaults to
`/etc/elasticsearch`. The location of the config directory can also be changed
2017-08-15 05:19:06 +08:00
via the `ES_PATH_CONF` environment variable, but note that setting this in your
2018-03-06 22:50:11 +08:00
shell is not sufficient. Instead, this variable is sourced from
2017-08-01 08:52:23 +08:00
`/etc/default/elasticsearch` (for the Debian package) and
`/etc/sysconfig/elasticsearch` (for the RPM package). You will need to edit the
2017-08-15 05:19:06 +08:00
`ES_PATH_CONF=/etc/elasticsearch` entry in one of these files accordingly to
change the config directory location.
2017-08-01 08:52:23 +08:00
2020-07-23 23:48:22 +08:00
[discrete]
2016-04-03 22:09:24 +08:00
=== Config file format
2013-08-29 07:24:34 +08:00
2020-08-01 03:58:38 +08:00
The configuration format is https://yaml.org/[YAML]. Here is an
2016-04-03 22:09:24 +08:00
example of changing the path of the data and logs directories:
2013-08-29 07:24:34 +08:00
2013-10-17 17:54:36 +08:00
[source,yaml]
2013-08-29 07:24:34 +08:00
--------------------------------------------------
path:
2016-04-03 22:09:24 +08:00
data: /var/lib/elasticsearch
2016-05-13 04:42:27 +08:00
logs: /var/log/elasticsearch
2013-08-29 07:24:34 +08:00
--------------------------------------------------
2016-04-03 22:09:24 +08:00
Settings can also be flattened as follows:
2013-08-29 07:24:34 +08:00
2013-10-17 17:54:36 +08:00
[source,yaml]
2013-08-29 07:24:34 +08:00
--------------------------------------------------
2016-04-03 22:09:24 +08:00
path.data: /var/lib/elasticsearch
2016-05-13 04:42:27 +08:00
path.logs: /var/log/elasticsearch
2013-08-29 07:24:34 +08:00
--------------------------------------------------
2020-10-16 04:28:35 +08:00
In YAML, you can format non-scalar values as sequences:
[source,yaml]
----
discovery.seed_hosts:
- 192.168.1.10:9300
- 192.168.1.11
- seeds.mydomain.com
----
Though less common, you can also format non-scalar values as arrays:
[source,yaml]
----
discovery.seed_hosts: ["192.168.1.10:9300", "192.168.1.11", "seeds.mydomain.com"]
----
2020-07-23 23:48:22 +08:00
[discrete]
2017-05-19 22:49:56 +08:00
=== Environment variable substitution
2013-08-29 07:24:34 +08:00
2016-04-03 22:09:24 +08:00
Environment variables referenced with the `${...}` notation within the
configuration file will be replaced with the value of the environment
2020-06-05 22:10:26 +08:00
variable. For example:
2013-08-29 07:24:34 +08:00
2013-10-17 17:54:36 +08:00
[source,yaml]
2013-08-29 07:24:34 +08:00
--------------------------------------------------
2016-04-03 22:09:24 +08:00
node.name: ${HOSTNAME}
network.host: ${ES_NETWORK_HOST}
2013-08-29 07:24:34 +08:00
--------------------------------------------------
2020-05-20 00:10:59 +08:00
2021-04-29 09:30:32 +08:00
Values for environment variables must be simple strings. Use a comma-separated string to provide values that {es} will parse as a list. For example, {es} will split the following string into a list of values for the `${HOSTNAME}` environment variable:
2020-06-05 22:10:26 +08:00
[source,yaml]
----
2021-11-04 02:02:34 +08:00
export HOSTNAME="host1,host2"
2020-06-05 22:10:26 +08:00
----
2020-05-20 00:10:59 +08:00
[discrete]
[[cluster-setting-types]]
=== Cluster and node setting types
Cluster and node settings can be categorized based on how they are configured:
[[dynamic-cluster-setting]]
Dynamic::
+
2020-08-24 20:42:45 +08:00
--
2022-01-19 01:32:43 +08:00
// tag::cluster-setting-precedence[]
2020-08-24 20:42:45 +08:00
You can configure and update dynamic settings on a running cluster using the
2022-01-19 01:32:43 +08:00
ifdef::strip-api-link[]
cluster update settings API.
endif::strip-api-link[]
ifndef::strip-api-link[]
<<cluster-update-settings,cluster update settings API>>.
endif::strip-api-link[]
You can also configure dynamic settings locally on an unstarted or shut down
node using `elasticsearch.yml`.
2020-08-24 20:42:45 +08:00
Updates made using the cluster update settings API can be _persistent_, which
apply across cluster restarts, or _transient_, which reset after a cluster
restart. You can also reset transient or persistent settings by assigning them
a `null` value using the API.
If you configure the same setting using multiple methods, {es} applies the
settings in following order of precedence:
1. Transient setting
2. Persistent setting
3. `elasticsearch.yml` setting
4. Default setting value
For example, you can apply a transient setting to override a persistent setting
or `elasticsearch.yml` setting. However, a change to an `elasticsearch.yml`
setting will not override a defined transient or persistent setting.
2021-10-26 23:57:42 +08:00
[TIP]
====
If you use {ess}, use the {cloud}/ec-add-user-settings.html[user settings]
feature to configure all cluster settings. This method lets {ess} automatically
reject unsafe settings that could break your cluster.
2022-01-19 01:32:43 +08:00
If you run {es} on your own hardware, use the
ifdef::strip-api-link[]
cluster update settings API
endif::strip-api-link[]
ifndef::strip-api-link[]
<<cluster-update-settings,cluster update settings API>>
endif::strip-api-link[]
to configure dynamic cluster settings. Only use `elasticsearch.yml` for static
cluster settings and node settings. The API doesn't require a restart and
ensures a setting's value is the same on all nodes.
2021-10-26 23:57:42 +08:00
====
2021-10-16 01:00:52 +08:00
2021-11-17 05:00:13 +08:00
include::{es-repo-dir}/cluster/update-settings.asciidoc[tag=transient-settings-warning]
2022-01-19 01:32:43 +08:00
// end::cluster-setting-precedence[]
2020-08-24 20:42:45 +08:00
--
2020-05-20 00:10:59 +08:00
[[static-cluster-setting]]
Static::
Static settings can only be configured on an unstarted or shut down node using
`elasticsearch.yml`.
+
Static settings must be set on every relevant node in the cluster.