ElasticSearch之Merge

发布时间 2023-11-30 22:38:10作者: jackieathome

Elasticsearchshard,即对应Luceneindex
Luceneindex由多个segment组成。
segmentindex保存数据的最小单位,不支持修改。

Elasticsearch在运行过程中,启动后台任务,周期性检测并将占用空间小的segment自动合并至大一些的segment,避免存在过多的segment对象,同时在合并过程中,会剔除掉已删除的记录。

合并操作的过程可能消耗较多的资源,比如CPU和I/O,因此在合并操作运行的过程中,Elasticsearch会自动调整合并操作的吞吐量,优先保证其它业务的正常运行。

Elasticsearch提供了ConcurrentMergeScheduler作为合并操作的调度器,管理合并操作的产生和运行。

ConcurrentMergeScheduler在新的线程中提交合并操作,同时控制合并操作的并发数。当合并操作占用的线程的数量达到index.merge.scheduler.max_thread_countConcurrentMergeScheduler将后续待执行的合并操作放至队列中,避免合并操作占用过多的资源,影响其它操作。

相关参数

index.merge.scheduler.max_thread_count
在一个shard上执行merge操作时允许使用的线程的数量。
默认值为Math.max(1, Math.min(4, node.processors / 2))

修改参数的取值,执行命令如下:

curl -X PUT "https://localhost:9200/_settings?pretty" -H 'Content-Type: application/json' -d'
{
    "index.merge.scheduler.max_thread_count": 2
}
' --cacert $ES_HOME/config/certs/http_ca.crt -u "elastic:ohCxPH=QBE+s5=*lo7F9"

假如当前没有创建index,则报错信息如下:

{
  "error" : {
    "root_cause" : [
      {
        "type" : "index_not_found_exception",
        "reason" : "no such index [[]]",
        "index_uuid" : "_na_",
        "index" : "[]"
      }
    ],
    "type" : "index_not_found_exception",
    "reason" : "no such index [[]]",
    "index_uuid" : "_na_",
    "index" : "[]"
  },
  "status" : 404
}

假如当前已有创建好的index,执行结果的样例,如下:

{
  "acknowledged" : true
}

相关资料