Elasticsearch

1. API

Elasticsearch 的 API 在官方文档上有很详细的介绍,我这里仅列举出平时用到的较多的 API,方便查询。

滚动升级集群

# 首先关闭 shard 的分配
PUT _cluster/settings
{
  "persistent": {
    "cluster.routing.allocation.enable": "none"
  }
}

# 然后写入硬盘
POST _flush/synced

# 升级完成后打开
PUT _cluster/settings
{
  "persistent": {
    "cluster.routing.allocation.enable": null
  }
}

Query API

Cat API

Index API

Cluster API

Shard Allocation

参考 Cluster level shard allocationDisk-based shard allocation

  • cluster.routing.allocation.enable

    • all - (default) Allows shard allocation for all kinds of shards.

    • primaries - Allows shard allocation only for primary shards.

    • new_primaries - Allows shard allocation only for primary shards for new indices.

    • none - No shard allocations of any kind are allowed for any indices.

  • cluster.routing.rebalance.enable

    • all - (default) Allows shard balancing for all kinds of shards.

    • primaries - Allows shard balancing only for primary shards.

    • replicas - Allows shard balancing only for replica shards.

    • none - No shard balancing of any kind are allowed for any indices.

  • cluster.routing.allocation.allow_rebalance

    • always - Always allow rebalancing.

    • indices_primaries_active - Only when all primaries in the cluster are allocated.

    • indices_all_active - (default) Only when all shards (primaries and replicas) in the cluster are allocated.

  • cluster.routing.allocation.disk.threshold_enabled

    • true - default

    • false

  • index.unassigned.node_left.delayed_timeout

    • 见 Index API。

    • 注意:此配置是 index 级别的,所以就算配置的时候指定为_all新建的 index 也不会有这个配置。可以用 template 的方式增加此配置。

2. Tuning

  • index.refresh_interval:由 Buffer 写入 Segment(在 OS cache 中) 的频率,默认 1s。

  • index.merge.scheduler.max_thread_count:merge 操作的最大线程,默认有个公式,详情参考官方

  • index.translog.durability:默认 request,表示同步写入,参考官方文档

  • index.translog.sync_interval:默认 5s,表示 translog 由 OS cache 写入硬盘的频率。需要 close index 才能修改。

对于已存在的 index:

对于以后创建的 index:

  • order:数值越大越后执行,会覆盖数值小的。

Last updated

Was this helpful?