# Elasticsearchでのforcemergeについて

**URL:** <https://discuss.elastic.co/t/elasticsearch-forcemerge/360827>\
**Category:** 日本語による質問・議論はこちら\
**Created:** [June 5, 2024, 7:07am UTC](https://discuss.elastic.co/t/elasticsearch-forcemerge/360827 "2024-06-05T07:07:17Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![hmdkns](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/hmdkns/32/135042_2.png) [@hmdkns](https://discuss.elastic.co/u/hmdkns)\
**Post date:** [June 5, 2024, 7:07am UTC](https://discuss.elastic.co/t/elasticsearch-forcemerge/360827/1 "2024-06-05T07:07:17Z")

</div>

elasticsearch 7.16.2 を使用していて、ドキュメントを大量に削除しディスクの空きを確保したいので、forcemergeを実行したのですが、ディスクの空きも増えず、logにもそれらしい情報は出力されていません。  
考えられる原因等ご教示願えませんでしょうか？

以下のコマンドを実行しており、docs.deletedの数が46573件あるので、forcemergeにより、これが0件になると考えております。  
'''  
curl -X GET "localhost:xxxx/\_cat/indices?v=true"  
health status index uuid pri rep docs.count docs.deleted store.size  
green open indexname\_xxxx X6zIqaOqRwmSu30XLXJ\_bw 9 0 720845 46573 73.1gb  
'''

以下のようにforcemergeを実行するとコマンドは成功しているように見えます。  
'''  
curl -X POST "localhost:xxxx/indexname\_xxxx/\_forcemerge?pretty"  
{  
"\_shards" : {  
"total" : 9,  
"successful" : 9,  
"failed" : 0  
}  
}  
'''

logには定期的に以下が出力されています。  
[2024-06-05T12:20:22,937][WARN][o.e.m.f.FsHealthService] [node-17] health check of [D:\elasticsearch-7.16.2\data\nodes\0] took [14415ms] which is above the warn threshold of [5s]  
[2024-06-05T12:30:36,574][WARN][o.e.t.ThreadPool] [node-17] execution of [ReschedulingRunnable{runnable=org.elasticsearch.watcher.ResourceWatcherService$ResourceMonitor@3b16e54f, interval=5s}] took [8127ms] which is above the warn threshold of [5000ms]

以上、よろしくお願いいたします。

---

<div class="post-metadata">

**Author:** ![hmdkns](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/hmdkns/32/135042_2.png) [@hmdkns](https://discuss.elastic.co/u/hmdkns)\
**Post date:** [June 5, 2024, 7:12am UTC](https://discuss.elastic.co/t/elasticsearch-forcemerge/360827/2 "2024-06-05T07:12:20Z")

</div>

定期的に以下のログが出力されています。

[2024-06-05T12:20:22,937][WARN][o.e.m.f.FsHealthService] [node-17] health check of [D:\elasticsearch-7.16.2\data\nodes\0] took [14415ms] which is above the warn threshold of [5s]  
[2024-06-05T12:30:36,574][WARN][o.e.t.ThreadPool] [node-17] execution of [ReschedulingRunnable{runnable=org.elasticsearch.watcher.ResourceWatcherService$ResourceMonitor@3b16e54f, interval=5s}] took [8127ms] which is above the warn threshold of [5000ms]

---

<div class="post-metadata">

**Author:** ![JOSEPH\_KIM](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/joseph_kim/32/137518_2.png) [@JOSEPH\_KIM](https://discuss.elastic.co/u/JOSEPH_KIM)\
**Post date:** [September 11, 2024, 8:11am UTC](https://discuss.elastic.co/t/elasticsearch-forcemerge/360827/3 "2024-09-11T08:11:11Z")

</div>

@hmdkns さん、  
お疲れ様です。 Joseph Kimと申します。

ForceMergeに関してはここに私なりの回答をつけました。

> [@elasticsearchでのforcemergeについて](https://discuss.elastic.co/t/elasticsearch-forcemerge/360855/2):
>
> @hmdkns さん、 お疲れ様です。 Joseph Kimと申します。 forcemergeによるディスクの空き容量を確保を意図されましたが、予測と違って空き空間が増えなかったことでお困りだと認識しました。 私の理解ですと、 Force Mergeは、複数の小さなセグメントを1つにまとめ、セグメント数を減らす作業です。この過程で不要なメタデータが削除され、一部のスペースを節約できますが、容量が大幅に減少することはおそらく難しいと考えています。 その理由は、 Force Mergeを行ってもデータ自体は維持されると思うからです。Force Mergeはデータを削除したり圧縮したりするのではなく、セグメントを再構成する作業です。そのため、実際のデータが占めるスペースは大きく変わらないと思います。 Force Mergeを行うことでセグメントの数が減るので、検索の性能は上がるかと思いますが、実際のDataの量は減らないので、空き空間を確保されたい場合は、物理的にSpaceを追加することが良いかと個人的に思いました。 お役に立てていれば幸いです。 Joseph Kim

定期的に出るログに関しては、何らかの理由で該当NodeへのHealthチェックが想定されていた時間より遅延されてResponseを返しているように見えます。（期待時間：５秒、実際時間：8.127秒）おそらく、ForceMergeによる激しいI/OやCPU使用量などで該当Nodeのリソースが足りなくなり、Response遅延が発生するのではないかと個人的に推測しています。

お役に立てていれば幸いです。

Joseph Kim
