Hello all,
This case mainly talks about "Disk Storage Space Is Not Released After Documents Are Deleted from Elasticsearch"
Applicable Version
6.5.x
Context and Symptom
A document of an index is deleted on Elasticsearch. After the document is deleted, the disk space is not released but may occupy more space.
1. The myindex-002 index occupies 8.6 GB disk space before its document is deleted.

2. After half of the files are deleted, the occupied disk space increases to 10.4 GB.

3. After the segment merge is completed, the occupied disk space changes to 5.3 GB instead of the expected 4.3 GB.

Cause Analysis
1. Each segment of Elasticsearch maintains a .del file. When the document is deleted on Elasticsearch, the document is marked as deleted in the .del file but its data is not cleared on the disk.
2. When Elasticsearch performs segment merge, segments are selected and merged to generate a new segment. In this case, the documents marked as deleted are not processed. Therefore, the disk space is released. By default, Elasticsearch selects some segments for merging. Therefore, the disk space is completely released only after all segments are processed.
3. You can set max_num_segments to 1 and perform the force merge operation to trigger Elasticsearch to process all segments of the index.
Solution
Perform the forcemerge operation and set max_num_segments to 1 to merge the indexes into one segment. In this way, the space can be completely released and the query performance can be improved.
curl -XPOST --negotiate -k -u : "https://ip:port//{index_name}/_forcemerge?max_num_segments=1"Note: Segment merging consumes CPU and a large number of I/O resources. Therefore, you are advised to perform segment merging during off-peak hours.
Any solutions will be appreciated!