How to reduce segment file number in Elasticsearch?

I want to reduce segments file number. There are too many little segment files in a shard. My settings are over here:

{
    "merge": {
        "scheduler": {
            "max_thread_count": "1",
            "max_merge_count": "100"
        },
        "policy": {
            "max_merge_at_once": "30",
            "max_merged_segment": "5GB",
            "segments_per_tier": "50",
            "floor_segment": "100mb"
        }
    }
}

And I analyzed each shard in the index and found that the more data there is in the shard, the more segment files there are.
There are 30 shards in trans_order_202005, I want to reduce the number of segment files to improve query performance.

index              shard prirep segment  generation  docs.count docs.deleted    size size.memory committed searchable version compound
trans_order_202005 0     p       _7z6u       372198       2824            1    2.2mb       19698 true      true       7.7.0   true
trans_order_202005 0     p       _7zf6       372498       2867            5    2.2mb       19739 true      true       7.7.0   true
trans_order_202005 0     p       _8cf5       389345       2986           35    2.4mb       20430 true      true       7.7.0   true
trans_order_202005 0     p       _92uz       423611       3105           32    2.5mb       19270 true      true       7.7.0   true
trans_order_202005 0     p       _a9xu       479442       3032           68    2.4mb       20338 true      true       7.7.0   true
trans_order_202005 0     p       _asyf       504087       2940           33    2.3mb       19654 true      true       7.7.0   true
trans_order_202005 0     p       _az1b       511967       3228           75    2.6mb       19954 true      true       7.7.0   true
trans_order_202005 0     p       _b52u       519798       3076           44    2.4mb       20875 true      true       7.7.0   true
trans_order_202005 0     p       _b6mp       521809       3331           31    2.6mb       19342 true      true       7.7.0   true
trans_order_202005 0     p       _bcoa       529642       2854            2    2.2mb       18024 true      true       7.7.0   true
trans_order_202005 0     p       _biak       536924       3014           30    2.4mb       20544 true      true       7.7.0   true
trans_order_202005 0     p       _bmry       542734       3318           66    2.6mb       20106 true      true       7.7.0   true
trans_order_202005 0     p       _bva3       553755       3246           22    2.5mb       20745 true      true       7.7.0   true
trans_order_202005 0     p       _co55       591161       3268           58    2.6mb       20280 true      true       7.7.0   true
trans_order_202005 0     p       _cqwl       594741       3066           17    2.4mb       20831 true      true       7.7.0   true
trans_order_202005 0     p       _d9ej       618715       2798           27    2.2mb       19015 true      true       7.7.0   true
trans_order_202005 0     p       _d9fn       618755       2993           38    2.2mb       19654 true      true       7.7.0   true
trans_order_202005 0     p       _d9fx       618765       2811           23    2.2mb       19137 true      true       7.7.0   true
trans_order_202005 0     p       _d9g7       618775       2783           11    2.2mb       20013 true      true       7.7.0   true
trans_order_202005 0     p       _d9gh       618785       2827           19    2.2mb       18652 true      true       7.7.0   true
trans_order_202005 0     p       _dehz       625319       3118           66    2.5mb       19239 true      true       7.7.0   true
trans_order_202005 0     p       _dez7       625939       3489          559    2.9mb       21020 true      true       7.7.0   true
trans_order_202005 0     p       _dflp       626749       1426           83    1.1mb       17121 true      true       7.7.0   true
trans_order_202005 0     p       _dk83       632739       1663           22    1.3mb       18559 true      true       7.7.0   true
trans_order_202005 0     p       _dlob       634619       1121            4  970.2kb       17198 true      true       7.7.0   true
trans_order_202005 0     p       _dlov       634639       2184           16    1.8mb       17868 true      true       7.7.0   true
trans_order_202005 0     p       _dnok       637220       1082           37  951.5kb       16812 true      true       7.7.0   true
trans_order_202005 0     p       _dns0       637344          1            0   11.3kb        4285 true      true       7.7.0   true
trans_order_202005 0     p       _dns6       637350        137            2  149.8kb       16671 true      true       7.7.0   true
trans_order_202005 0     p       _dns7       637351          1            0     18kb        6113 true      true       7.7.0   true
trans_order_202005 0     p       _dns8       637352          1            0   18.1kb        6113 true      true       7.7.0   true
trans_order_202005 0     p       _dnsb       637355          2            0   18.2kb        6332 true      true       7.7.0   true
trans_order_202005 0     p       _dnsc       637356          1            0   18.8kb        6563 true      true       7.7.0   true
trans_order_202005 0     p       _dnse       637358     506809            1  346.4mb      759581 true      true       7.7.0   false
trans_order_202005 0     p       _dnsg       637360          1            0     19kb        6786 true      true       7.7.0   true
trans_order_202005 0     p       _dnsh       637361          1            0   19.1kb        6786 true      true       7.7.0   true
trans_order_202005 0     r       _6azv       294187       3538            3    2.4mb       17724 true      true       7.7.0   true
trans_order_202005 0     r       _7xr6       370338       3207            5    2.2mb       18003 true      true       7.7.0   true
trans_order_202005 0     r       _7xus       370468       2840           10    2.2mb       18106 true      true       7.7.0   true
trans_order_202005 0     r       _8oak       404732       2820            2    2.2mb       18349 true      true       7.7.0   true
trans_order_202005 0     r       _9e90       438372       2867            5    2.2mb       19355 true      true       7.7.0   true
trans_order_202005 0     r       _9ecw       438512       3050            1    2.2mb       20238 true      true       7.7.0   true
trans_order_202005 0     r       _9eea       438562       2891            8    2.2mb       18738 true      true       7.7.0   true
trans_order_202005 0     r       _9eev       438583       2856            1    2.2mb       19405 true      true       7.7.0   true
trans_order_202005 0     r       _ad9l       483753       2920            1    2.2mb       19186 true      true       7.7.0   true
trans_order_202005 0     r       _aqax       500649       2897           67    2.3mb       18613 true      true       7.7.0   true
trans_order_202005 0     r       _bxpb       556895       2791            9    2.2mb       19594 true      true       7.7.0   true
trans_order_202005 0     r       _bxq5       556925       2834            9    2.2mb       21013 true      true       7.7.0   true
trans_order_202005 0     r       _bxqf       556935       2770           12    2.2mb       18108 true      true       7.7.0   true
trans_order_202005 0     r       _bxqz       556955       2809            3    2.2mb       18836 true      true       7.7.0   true
trans_order_202005 0     r       _bxr9       556965       2795            9    2.2mb       19536 true      true       7.7.0   true
trans_order_202005 0     r       _bxrj       556975       2784            7    2.2mb       20038 true      true       7.7.0   true
trans_order_202005 0     r       _bxrt       556985       2754           19    2.2mb       20197 true      true       7.7.0   true
trans_order_202005 0     r       _bxs3       556995       2831            9    2.2mb       19911 true      true       7.7.0   true
trans_order_202005 0     r       _ctoz       598355       2784           55    2.2mb       18139 true      true       7.7.0   true
trans_order_202005 0     r       _ctp9       598365       2724           79    2.2mb       17890 true      true       7.7.0   true
trans_order_202005 0     r       _ctpj       598375       2733           63    2.2mb       19516 true      true       7.7.0   true
trans_order_202005 0     r       _ctpt       598385       2700           63    2.2mb       18626 true      true       7.7.0   true
trans_order_202005 0     r       _d6t8       615356       2237          107    1.8mb       17564 true      true       7.7.0   true
trans_order_202005 0     r       _dfd1       626437       2885          333    2.3mb       19558 true      true       7.7.0   true
trans_order_202005 0     r       _di2t       629957       2394           28    1.9mb       18095 true      true       7.7.0   true
trans_order_202005 0     r       _dmen       635567       2032           33    1.6mb       17120 true      true       7.7.0   true
trans_order_202005 0     r       _dmex       635577       2007           52    1.6mb       17670 true      true       7.7.0   true
trans_order_202005 0     r       _dmf7       635587       2015           23    1.6mb       17247 true      true       7.7.0   true
trans_order_202005 0     r       _do2g       637720       1934            3    1.5mb       19760 true      true       7.7.0   true
trans_order_202005 0     r       _do2h       637721          1            0   17.5kb        5888 true      true       7.7.0   true
trans_order_202005 0     r       _do2i       637722          1            0     18kb        6113 true      true       7.7.0   true
trans_order_202005 0     r       _do2j       637723          1            0   18.1kb        6113 true      true       7.7.0   true
trans_order_202005 0     r       _do2m       637726          1            0   17.2kb        6332 true      true       7.7.0   true
trans_order_202005 0     r       _do2n       637727          1            0   17.2kb        6332 true      true       7.7.0   true
trans_order_202005 0     r       _do2o       637728          1            0   18.8kb        6563 true      true       7.7.0   true
trans_order_202005 0     r       _do2q       637730     502697            1  344.1mb      757432 true      true       7.7.0   false
trans_order_202005 0     r       _do2s       637732          1            0     19kb        6786 true      true       7.7.0   true
trans_order_202005 0     r       _do2t       637733          1            0   19.1kb        6786 true      true       7.7.0   true

Maybe this helps:
https://www.elastic.co/guide/en/elasticsearch/reference/current/indices-forcemerge.html

Welcome to our community! :smiley:

What do you mean by too many? Why is it too many? What problems is it causing?

Thanks, I need an auto-merge strategy.

I wonder why there are so many files of different sizes that seem to be exponential, I think it will affect query performance

Unless you are seeing issues, the default merge policy is fine.

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.