错误信息:
org.springframework.data.elasticsearch.ElasticsearchException: Bulk indexing has failures. Use ElasticsearchException.getFailedDocuments() for detailed messages [{970893=RemoteTransportException[[node-1][127.0.0.1:9300][indices:data/write/bulk[s][p]]]; nested: EsRejectedExecutionException[rejected execution of org.elasticsearch.transport.TransportService$7@4e8e5243 on EsThreadPoolExecutor[bulk, queue capacity = 200, org.elasticsearch.common.util.concurrent.EsThreadPoolExecutor@78ffd538[Running, pool size = 1, active threads = 1, queued tasks = 200, completed tasks = 1104226]]];,
解决方法:
查看各节点线程池配置
GET /ES地址/_nodes/thread_pool/
执行上述命令查看线程池配置:
{"_nodes":{"total":1,"successful":1,"failed":0},"cluster_name":"my-application","nodes":{"OKYdCPdRQMSCUWaXn-RXuA":{"name":"node-1","transport_address":"127.0.0.1:9300","host":"127.0.0.1","ip":"127.0.0.1","version":"6.0.0","build_hash":"8f0685b","roles":["master","data","ingest"],"thread_pool":{"force_merge":{"type":"fixed","min":1,"max":1,"queue_size":-1},"fetch_shard_started":{"type":"scaling","min":1,"max":2,"keep_alive":"5m","queue_size":-1},"listener":{"type":"fixed","min":1,"max":1,"queue_size":-1},"index":{"type":"fixed","min":1,"max":1,"queue_size":200},"refresh":{"type":"scaling","min":1,"max":1,"keep_alive":"5m","queue_size":-1},"generic":{"type":"scaling","min":4,"max":128,"keep_alive":"30s","queue_size":-1},"warmer":{"type":"scaling","min":1,"max":1,"keep_alive":"5m","queue_size":-1},"search":{"type":"fixed_auto_queue_size","min":2,"max":2,"queue_size":1000},"flush":{"type":"scaling","min":1,"max":1,"keep_alive":"5m","queue_size":-1},"fetch_shard_store":{"type":"scaling","min":1,"max":2,"keep_alive":"5m","queue_size":-1},"management":{"type":"scaling","min":1,"max":5,"keep_alive":"5m","queue_size":-1},"get":{"type":"fixed","min":1,"max":1,"queue_size":1000},"bulk":{"type":"fixed","min":1,"max":1,"queue_size":200},"snapshot":{"type":"scaling","min":1,"max":1,"keep_alive":"5m","queue_size":-1}}}}}
可以看到我们线程池的配置如下:
“bulk”:{“type”:“fixed”,“min”:1,“max”:1,“queue_size”:200}
下一步:
修改线程池的配置:
PUT /_cluster/settings
{
“transient”: {
“threadpool.bulk.type”: “fixed”,
“threadpool.bulk.queue_size”: 1000,
“threadpool.bulk.size”: 128,
“threadpool.bulk.min”: 128,
“threadpool.bulk.max”: 128
}
}
发现报了如下错误:transient setting [threadpool.bulk.max], not dynamically updateable,
原来是queue_size参数并不能通过api来更改了,需要修改配置文件并且重启机器。
注意 thread_pool.bulk.size 不可以超过cpu核数的2倍,修改配置如下,重启之后就OK。
thread_pool.bulk.queue_size: 10000
thread_pool.bulk.size: 16