{"id":16597,"date":"2023-03-31T21:45:00","date_gmt":"2023-03-31T16:15:00","guid":{"rendered":"https:\/\/blogrevamp.cashfree.com\/?p=16597"},"modified":"2023-04-18T13:32:57","modified_gmt":"2023-04-18T08:02:57","slug":"optimising-elasticsearch-storage","status":"publish","type":"post","link":"https:\/\/blogrevamp.cashfree.com\/optimising-elasticsearch-storage\/","title":{"rendered":"Optimising Elastic Search Storage for Search Performance"},"content":{"rendered":"<div id=\"ez-toc-container\" class=\"ez-toc-v2_0_81 counter-hierarchy ez-toc-counter ez-toc-custom ez-toc-container-direction\">\n<div class=\"ez-toc-title-container\">\n<p class=\"ez-toc-title\" style=\"cursor:inherit\">Table of Contents<\/p>\n<span class=\"ez-toc-title-toggle\"><a href=\"#\" class=\"ez-toc-pull-right ez-toc-btn ez-toc-btn-xs ez-toc-btn-default ez-toc-toggle\" aria-label=\"Toggle Table of Content\"><span class=\"ez-toc-js-icon-con\"><span class=\"\"><span class=\"eztoc-hide\" style=\"display:none;\">Toggle<\/span><span class=\"ez-toc-icon-toggle-span\"><svg style=\"fill: #005c31;color:#005c31\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" class=\"list-377408\" width=\"20px\" height=\"20px\" viewBox=\"0 0 24 24\" fill=\"none\"><path d=\"M6 6H4v2h2V6zm14 0H8v2h12V6zM4 11h2v2H4v-2zm16 0H8v2h12v-2zM4 16h2v2H4v-2zm16 0H8v2h12v-2z\" fill=\"currentColor\"><\/path><\/svg><svg style=\"fill: #005c31;color:#005c31\" class=\"arrow-unsorted-368013\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"10px\" height=\"10px\" viewBox=\"0 0 24 24\" version=\"1.2\" baseProfile=\"tiny\"><path d=\"M18.2 9.3l-6.2-6.3-6.2 6.3c-.2.2-.3.4-.3.7s.1.5.3.7c.2.2.4.3.7.3h11c.3 0 .5-.1.7-.3.2-.2.3-.5.3-.7s-.1-.5-.3-.7zM5.8 14.7l6.2 6.3 6.2-6.3c.2-.2.3-.5.3-.7s-.1-.5-.3-.7c-.2-.2-.4-.3-.7-.3h-11c-.3 0-.5.1-.7.3-.2.2-.3.5-.3.7s.1.5.3.7z\"\/><\/svg><\/span><\/span><\/span><\/a><\/span><\/div>\n<nav><ul class='ez-toc-list ez-toc-list-level-1 ' ><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-1\" href=\"https:\/\/blogrevamp.cashfree.com\/optimising-elasticsearch-storage\/#Introduction\" >Introduction<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-2\" href=\"https:\/\/blogrevamp.cashfree.com\/optimising-elasticsearch-storage\/#Elasticsearch_best_practices_used_in_reporting_services\" >Elasticsearch best practices used in reporting services<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-3\" href=\"https:\/\/blogrevamp.cashfree.com\/optimising-elasticsearch-storage\/#Why_do_we_need_to_optimise_elastic_indices\" >Why do we need to optimise elastic indices?<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-4\" href=\"https:\/\/blogrevamp.cashfree.com\/optimising-elasticsearch-storage\/#How_Did_We_Optimise_Elastic_Indices\" >How Did We Optimise Elastic Indices?<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-5\" href=\"https:\/\/blogrevamp.cashfree.com\/optimising-elasticsearch-storage\/#Note\" >Note:&nbsp;&nbsp;<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-6\" href=\"https:\/\/blogrevamp.cashfree.com\/optimising-elasticsearch-storage\/#Conclusion\" >Conclusion<\/a><\/li><\/ul><\/nav><\/div>\n\n<h2 class=\"wp-block-heading\" id=\"h-introduction\"><span class=\"ez-toc-section\" id=\"Introduction\"><\/span>Introduction<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">This blog continues our previous blog, <a href=\"https:\/\/www.cashfree.com\/blog\/reporting-systems-to-ensure-enhanced-customer-satisfaction\/\" target=\"_blank\" rel=\"noreferrer noopener\">How We Build Reporting Systems To Ensure Enhanced Customer Satisfaction<\/a>.&nbsp;&nbsp;<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">This blog describes the optimisation of Elasticsearch indices to improve search performance, sustain Elasticsearch\u2019s peak performance and optimise the hardware resources.<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img data-recalc-dims=\"1\" fetchpriority=\"high\" decoding=\"async\" width=\"770\" height=\"457\" data-attachment-id=\"16614\" data-permalink=\"https:\/\/blogrevamp.cashfree.com\/optimising-elasticsearch-storage\/report-indices_d7_2\/\" data-orig-file=\"https:\/\/i0.wp.com\/blogrevamp.cashfree.com\/wp-content\/uploads\/2023\/04\/Report-Indices_D7_2.png?fit=3456%2C2052&amp;ssl=1\" data-orig-size=\"3456,2052\" data-comments-opened=\"1\" data-image-meta=\"{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;0&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;,&quot;orientation&quot;:&quot;0&quot;}\" data-image-title=\"Report-Indices_D7_2\" data-image-description=\"\" data-image-caption=\"\" data-large-file=\"https:\/\/i0.wp.com\/blogrevamp.cashfree.com\/wp-content\/uploads\/2023\/04\/Report-Indices_D7_2.png?fit=770%2C457&amp;ssl=1\" src=\"https:\/\/i0.wp.com\/blogrevamp.cashfree.com\/wp-content\/uploads\/2023\/04\/Report-Indices_D7_2.png?resize=770%2C457&#038;ssl=1\" alt=\"\" class=\"wp-image-16614\" srcset=\"https:\/\/i0.wp.com\/blogrevamp.cashfree.com\/wp-content\/uploads\/2023\/04\/Report-Indices_D7_2.png?resize=1024%2C608&amp;ssl=1 1024w, https:\/\/i0.wp.com\/blogrevamp.cashfree.com\/wp-content\/uploads\/2023\/04\/Report-Indices_D7_2.png?resize=300%2C178&amp;ssl=1 300w, https:\/\/i0.wp.com\/blogrevamp.cashfree.com\/wp-content\/uploads\/2023\/04\/Report-Indices_D7_2.png?resize=768%2C456&amp;ssl=1 768w, https:\/\/i0.wp.com\/blogrevamp.cashfree.com\/wp-content\/uploads\/2023\/04\/Report-Indices_D7_2.png?resize=1536%2C912&amp;ssl=1 1536w, https:\/\/i0.wp.com\/blogrevamp.cashfree.com\/wp-content\/uploads\/2023\/04\/Report-Indices_D7_2.png?w=2310&amp;ssl=1 2310w\" sizes=\"(max-width: 770px) 100vw, 770px\" \/><\/figure>\n\n\n\n<h3 class=\"wp-block-heading\">Indices<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Indices are where data is stored in Elasticsearch. One index is made up of one or many shards.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Shards<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Shard is an instance of a Lucene index, which you can think of as a self-contained search engine that indexes and handles queries for a subset of the data of the index it belongs to. There are two types of shards:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Primary shard: Holds the part of data stored in an index.&nbsp;<\/li>\n\n\n\n<li>Replica shard: Redundant copies of the primary shard that improve query performance, and protect against hardware failures.<\/li>\n<\/ul>\n\n\n\n<h3 class=\"wp-block-heading\">Choosing the number of shards<\/h3>\n\n\n\n<ol class=\"wp-block-list\">\n<li>A common approach is to start with one shard and keep increasing the number until you achieve the highest performance.<\/li>\n\n\n\n<li>If you have 2 data nodes, you should have 2, 4, or 6 shards. If you have decided to use 3 primary shards, then your indexing process will actually be slower than when using 2 shards, because 1 node will have double the work.&nbsp;<\/li>\n\n\n\n<li>20-25 GB is usually a good shard size for search operations.<\/li>\n<\/ol>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Elasticsearch_best_practices_used_in_reporting_services\"><\/span>Elasticsearch best practices used in reporting services<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<h3 class=\"wp-block-heading\">How do we create indices<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">We have defined an interval to create a new index at a day, week, fortnight, month, quarter, and year level based on the volume of data in the index.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Multiple primary shards when indexing<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">When you send a bulk request to index a list of documents, they will be divided among all available primary shards.&nbsp;<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">For example, if you have 4 primary shards and send a request with 80 documents, each shard will index 20 documents in parallel. Once all documents are indexed, the response is sent back to the client.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Multiple primary shards when searching<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">How does parallelisation work for searching? Each shard contains only a subset of the documents. When you submit a search request, the node that receives the request acts as the coordinating node, which then looks&nbsp; into the cluster state to find all the shards that make up the index. The coordinating node will then dispatch that query to all of those shards.&nbsp;<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">After that, each shard locally computes a list of results with document IDs and scores. Those partial results are sent back to the coordinating node which merges them into a single result. Then, the second phase begins, where a list of documents gets fetched.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Why_do_we_need_to_optimise_elastic_indices\"><\/span>Why do we need to optimise elastic indices?<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<h3 class=\"wp-block-heading\">Quick exhaustion of the shards<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">In our reporting service, on average, we create 6 indices every day which takes 40 shards, each index having a different primary and replica shard count based on data volume and traffic. For a year, it will be&nbsp; 6*365=2190 indices and 40*365= 14600 shards and our retention period is 2 years, or even more for some of the indices.&nbsp;<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">As you see, 14600 shards are required in one year. Each shard utilises some resources for mapping, storing cluster states, querying, etc. The higher the number of shards, the greater the resource utilisation, and keeping too many active shards in the Elasticsearch cluster will degrade the overall performance of Elasticsearch.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Search performance<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Usually, writing happens once and reading happens numerous times. In fact, most of the data is immutable a few days after it is written and some of them are immutable immediately.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Let&#8217;s assume you have a day-level index order and you will have millions of orders daily. So, you need fast ingestion for a day or for a few days. Then, you will have mostly read traffic.&nbsp;&nbsp;<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">In the above scenario, you can create the index with more primary shards based on the data volume and ingestion traffic. As you have already seen above, having multiple shards when searching will have performance issues, this is where the index optimisation is required once the index will not incur any more write.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"How_Did_We_Optimise_Elastic_Indices\"><\/span>How Did We Optimise Elastic Indices?<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">We have used shrink API and force-merge API of Elasticsearch to optimise indices.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">We have implemented an index optimiser as part of our application which will be running on a scheduled basis when the traffic is less. The optimisation process is as follows:<br><strong>Update index setting<\/strong>: Before you can shrink an index, the index must be read-only. A copy of every shard in the index must reside on the same node and the index must have a green <a href=\"https:\/\/www.elastic.co\/guide\/en\/elasticsearch\/reference\/7.17\/cluster-health.html\" target=\"_blank\" rel=\"noreferrer noopener nofollow\">health status<\/a>. Also, it is recommended to remove the replicas to make the shard allocation easier.&nbsp;<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img data-recalc-dims=\"1\" decoding=\"async\" width=\"770\" height=\"290\" data-attachment-id=\"16601\" data-permalink=\"https:\/\/blogrevamp.cashfree.com\/optimising-elasticsearch-storage\/report-indices_d1\/\" data-orig-file=\"https:\/\/i0.wp.com\/blogrevamp.cashfree.com\/wp-content\/uploads\/2023\/04\/Report-Indices_D1.png?fit=3473%2C1305&amp;ssl=1\" data-orig-size=\"3473,1305\" data-comments-opened=\"1\" data-image-meta=\"{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;0&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;,&quot;orientation&quot;:&quot;0&quot;}\" data-image-title=\"Report-Indices_D1\" data-image-description=\"\" data-image-caption=\"\" data-large-file=\"https:\/\/i0.wp.com\/blogrevamp.cashfree.com\/wp-content\/uploads\/2023\/04\/Report-Indices_D1.png?fit=770%2C290&amp;ssl=1\" src=\"https:\/\/i0.wp.com\/blogrevamp.cashfree.com\/wp-content\/uploads\/2023\/04\/Report-Indices_D1.png?resize=770%2C290&#038;ssl=1\" alt=\"\" class=\"wp-image-16601\" srcset=\"https:\/\/i0.wp.com\/blogrevamp.cashfree.com\/wp-content\/uploads\/2023\/04\/Report-Indices_D1.png?resize=1024%2C385&amp;ssl=1 1024w, https:\/\/i0.wp.com\/blogrevamp.cashfree.com\/wp-content\/uploads\/2023\/04\/Report-Indices_D1.png?resize=300%2C113&amp;ssl=1 300w, https:\/\/i0.wp.com\/blogrevamp.cashfree.com\/wp-content\/uploads\/2023\/04\/Report-Indices_D1.png?resize=768%2C289&amp;ssl=1 768w, https:\/\/i0.wp.com\/blogrevamp.cashfree.com\/wp-content\/uploads\/2023\/04\/Report-Indices_D1.png?resize=1536%2C577&amp;ssl=1 1536w, https:\/\/i0.wp.com\/blogrevamp.cashfree.com\/wp-content\/uploads\/2023\/04\/Report-Indices_D1.png?w=2310&amp;ssl=1 2310w\" sizes=\"(max-width: 770px) 100vw, 770px\" \/><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Shrink index<\/strong>: The shrink index API allows you to shrink an existing index into a new index with fewer primary shards. The requested number of primary shards in the target index must be a factor in the number of shards in the source index. For example, an index with 8 primary shards can be shrunk into 4, 2, or 1 primary shard.<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img data-recalc-dims=\"1\" decoding=\"async\" width=\"770\" height=\"290\" data-attachment-id=\"16603\" data-permalink=\"https:\/\/blogrevamp.cashfree.com\/optimising-elasticsearch-storage\/report-indices_d2\/\" data-orig-file=\"https:\/\/i0.wp.com\/blogrevamp.cashfree.com\/wp-content\/uploads\/2023\/04\/Report-Indices_D2.png?fit=3473%2C1306&amp;ssl=1\" data-orig-size=\"3473,1306\" data-comments-opened=\"1\" data-image-meta=\"{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;0&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;,&quot;orientation&quot;:&quot;0&quot;}\" data-image-title=\"Report-Indices_D2\" data-image-description=\"\" data-image-caption=\"\" data-large-file=\"https:\/\/i0.wp.com\/blogrevamp.cashfree.com\/wp-content\/uploads\/2023\/04\/Report-Indices_D2.png?fit=770%2C290&amp;ssl=1\" src=\"https:\/\/i0.wp.com\/blogrevamp.cashfree.com\/wp-content\/uploads\/2023\/04\/Report-Indices_D2.png?resize=770%2C290&#038;ssl=1\" alt=\"\" class=\"wp-image-16603\" srcset=\"https:\/\/i0.wp.com\/blogrevamp.cashfree.com\/wp-content\/uploads\/2023\/04\/Report-Indices_D2.png?resize=1024%2C385&amp;ssl=1 1024w, https:\/\/i0.wp.com\/blogrevamp.cashfree.com\/wp-content\/uploads\/2023\/04\/Report-Indices_D2.png?resize=300%2C113&amp;ssl=1 300w, https:\/\/i0.wp.com\/blogrevamp.cashfree.com\/wp-content\/uploads\/2023\/04\/Report-Indices_D2.png?resize=768%2C289&amp;ssl=1 768w, https:\/\/i0.wp.com\/blogrevamp.cashfree.com\/wp-content\/uploads\/2023\/04\/Report-Indices_D2.png?resize=1536%2C578&amp;ssl=1 1536w, https:\/\/i0.wp.com\/blogrevamp.cashfree.com\/wp-content\/uploads\/2023\/04\/Report-Indices_D2.png?w=2310&amp;ssl=1 2310w\" sizes=\"(max-width: 770px) 100vw, 770px\" \/><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">You can monitor shrink processes with <a href=\"https:\/\/www.elastic.co\/guide\/en\/elasticsearch\/reference\/7.17\/cluster-health.html\" target=\"_blank\" rel=\"noreferrer noopener nofollow\">cluster health API<\/a> to wait until all&nbsp; primary shards have been allocated by setting the <strong>wait_for_status <\/strong>parameter to yellow or green.<\/p>\n\n\n\n<ol class=\"wp-block-list\">\n<li><strong>Add an alias<\/strong>: As you can see from the shrink API, the target index name will be different from your source index name. If your application needs the same name then you can delete the existing source index and <a href=\"https:\/\/www.elastic.co\/guide\/en\/elasticsearch\/reference\/7.17\/indices-aliases.html\" target=\"_blank\" rel=\"noreferrer noopener nofollow\">add the alias<\/a> with the same name to the target index.<\/li>\n<\/ol>\n\n\n\n<ol class=\"wp-block-list\" start=\"2\">\n<li><strong>Merge segments<\/strong>: You can use the force merge API to reduce the number of segments in each shard by merging some of them together. This step also frees up the space used by deleted documents.<\/li>\n<\/ol>\n\n\n\n<p class=\"wp-block-paragraph\">In Lucene, a document is not deleted from a segment but just marked as deleted. During a merge, a new segment is created that does not contain those document deletions.<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" width=\"770\" height=\"97\" data-attachment-id=\"16606\" data-permalink=\"https:\/\/blogrevamp.cashfree.com\/optimising-elasticsearch-storage\/report-indices_d3\/\" data-orig-file=\"https:\/\/i0.wp.com\/blogrevamp.cashfree.com\/wp-content\/uploads\/2023\/04\/Report-Indices_D3.png?fit=3473%2C437&amp;ssl=1\" data-orig-size=\"3473,437\" data-comments-opened=\"1\" data-image-meta=\"{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;0&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;,&quot;orientation&quot;:&quot;0&quot;}\" data-image-title=\"Report-Indices_D3\" data-image-description=\"\" data-image-caption=\"\" data-large-file=\"https:\/\/i0.wp.com\/blogrevamp.cashfree.com\/wp-content\/uploads\/2023\/04\/Report-Indices_D3.png?fit=770%2C97&amp;ssl=1\" src=\"https:\/\/i0.wp.com\/blogrevamp.cashfree.com\/wp-content\/uploads\/2023\/04\/Report-Indices_D3.png?resize=770%2C97&#038;ssl=1\" alt=\"\" class=\"wp-image-16606\" srcset=\"https:\/\/i0.wp.com\/blogrevamp.cashfree.com\/wp-content\/uploads\/2023\/04\/Report-Indices_D3.png?resize=1024%2C129&amp;ssl=1 1024w, https:\/\/i0.wp.com\/blogrevamp.cashfree.com\/wp-content\/uploads\/2023\/04\/Report-Indices_D3.png?resize=300%2C38&amp;ssl=1 300w, https:\/\/i0.wp.com\/blogrevamp.cashfree.com\/wp-content\/uploads\/2023\/04\/Report-Indices_D3.png?resize=768%2C97&amp;ssl=1 768w, https:\/\/i0.wp.com\/blogrevamp.cashfree.com\/wp-content\/uploads\/2023\/04\/Report-Indices_D3.png?resize=1536%2C193&amp;ssl=1 1536w, https:\/\/i0.wp.com\/blogrevamp.cashfree.com\/wp-content\/uploads\/2023\/04\/Report-Indices_D3.png?w=2310&amp;ssl=1 2310w\" sizes=\"(max-width: 770px) 100vw, 770px\" \/><\/figure>\n\n\n\n<ol class=\"wp-block-list\">\n<li><strong>Add replica<\/strong>: We removed the replica before shrinking the index. Now, you can add one or more replicas based on your requirement.&nbsp;<\/li>\n<\/ol>\n\n\n\n<p class=\"wp-block-paragraph\">As you see, we have to execute multiple steps sequentially on indices as part of optimisation and some of the steps will be executed asynchronously, i.e. update setting, merge shards, merge segments, etc. Hence, we would be needing a way to track the steps of indices that will need optimisation. We have used ActiveMQ queue for the same. We have retry enabled at each step that will help to retry in case of failures.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Below table has the comparison, before and after index optimisation:<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" width=\"770\" height=\"444\" data-attachment-id=\"16608\" data-permalink=\"https:\/\/blogrevamp.cashfree.com\/optimising-elasticsearch-storage\/report-indices_d6_v2\/\" data-orig-file=\"https:\/\/i0.wp.com\/blogrevamp.cashfree.com\/wp-content\/uploads\/2023\/04\/Report-Indices_D6_V2.png?fit=3473%2C2006&amp;ssl=1\" data-orig-size=\"3473,2006\" data-comments-opened=\"1\" data-image-meta=\"{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;0&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;,&quot;orientation&quot;:&quot;0&quot;}\" data-image-title=\"Report-Indices_D6_V2\" data-image-description=\"\" data-image-caption=\"\" data-large-file=\"https:\/\/i0.wp.com\/blogrevamp.cashfree.com\/wp-content\/uploads\/2023\/04\/Report-Indices_D6_V2.png?fit=770%2C444&amp;ssl=1\" src=\"https:\/\/i0.wp.com\/blogrevamp.cashfree.com\/wp-content\/uploads\/2023\/04\/Report-Indices_D6_V2.png?resize=770%2C444&#038;ssl=1\" alt=\"\" class=\"wp-image-16608\" srcset=\"https:\/\/i0.wp.com\/blogrevamp.cashfree.com\/wp-content\/uploads\/2023\/04\/Report-Indices_D6_V2.png?resize=1024%2C591&amp;ssl=1 1024w, https:\/\/i0.wp.com\/blogrevamp.cashfree.com\/wp-content\/uploads\/2023\/04\/Report-Indices_D6_V2.png?resize=300%2C173&amp;ssl=1 300w, https:\/\/i0.wp.com\/blogrevamp.cashfree.com\/wp-content\/uploads\/2023\/04\/Report-Indices_D6_V2.png?resize=768%2C444&amp;ssl=1 768w, https:\/\/i0.wp.com\/blogrevamp.cashfree.com\/wp-content\/uploads\/2023\/04\/Report-Indices_D6_V2.png?resize=1536%2C887&amp;ssl=1 1536w, https:\/\/i0.wp.com\/blogrevamp.cashfree.com\/wp-content\/uploads\/2023\/04\/Report-Indices_D6_V2.png?w=2310&amp;ssl=1 2310w\" sizes=\"(max-width: 770px) 100vw, 770px\" \/><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Note\"><\/span>Note<strong>:&nbsp;&nbsp;<\/strong><span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Force merge should only be called against an index after you have finished writing to it. If you continue to write to such an index then the automatic merge policy will never consider these segments for future merges until they mostly consist of deleted documents. This can cause very large segments to remain in the index which can result in increased disk usage and worse search performance.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">If you have a use case where you need a write operation after force merges then you can allow the write operation. Then, you can run the below force merge API manually once a month to clean the deleted documents from segments since the automatic merge policy will not be considered.&nbsp;<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" width=\"770\" height=\"149\" data-attachment-id=\"16611\" data-permalink=\"https:\/\/blogrevamp.cashfree.com\/optimising-elasticsearch-storage\/report-indices_d5\/\" data-orig-file=\"https:\/\/i0.wp.com\/blogrevamp.cashfree.com\/wp-content\/uploads\/2023\/04\/Report-Indices_D5.png?fit=3473%2C672&amp;ssl=1\" data-orig-size=\"3473,672\" data-comments-opened=\"1\" data-image-meta=\"{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;0&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;,&quot;orientation&quot;:&quot;0&quot;}\" data-image-title=\"Report-Indices_D5\" data-image-description=\"\" data-image-caption=\"\" data-large-file=\"https:\/\/i0.wp.com\/blogrevamp.cashfree.com\/wp-content\/uploads\/2023\/04\/Report-Indices_D5.png?fit=770%2C149&amp;ssl=1\" src=\"https:\/\/i0.wp.com\/blogrevamp.cashfree.com\/wp-content\/uploads\/2023\/04\/Report-Indices_D5.png?resize=770%2C149&#038;ssl=1\" alt=\"\" class=\"wp-image-16611\" srcset=\"https:\/\/i0.wp.com\/blogrevamp.cashfree.com\/wp-content\/uploads\/2023\/04\/Report-Indices_D5.png?resize=1024%2C198&amp;ssl=1 1024w, https:\/\/i0.wp.com\/blogrevamp.cashfree.com\/wp-content\/uploads\/2023\/04\/Report-Indices_D5.png?resize=300%2C58&amp;ssl=1 300w, https:\/\/i0.wp.com\/blogrevamp.cashfree.com\/wp-content\/uploads\/2023\/04\/Report-Indices_D5.png?resize=768%2C149&amp;ssl=1 768w, https:\/\/i0.wp.com\/blogrevamp.cashfree.com\/wp-content\/uploads\/2023\/04\/Report-Indices_D5.png?resize=1536%2C297&amp;ssl=1 1536w, https:\/\/i0.wp.com\/blogrevamp.cashfree.com\/wp-content\/uploads\/2023\/04\/Report-Indices_D5.png?w=2310&amp;ssl=1 2310w\" sizes=\"(max-width: 770px) 100vw, 770px\" \/><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Conclusion\"><\/span>Conclusion<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">In this post, we shared our experience on how we optimised the indices to increase the search performance and keep the elastic search running at peak performance with fewer resources.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>This blog describes the optimisation of Elasticsearch indices to improve search performance, sustain Elasticsearch\u2019s peak performance and optimise the hardware resources.<\/p>\n","protected":false},"author":73,"featured_media":16616,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_exactmetrics_skip_tracking":false,"_exactmetrics_sitenote_active":false,"_exactmetrics_sitenote_note":"","_exactmetrics_sitenote_category":0,"_themeisle_gutenberg_block_has_review":false,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_wpcom_ai_launchpad_first_post":false,"_jetpack_feature_clip_id":0,"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_post_was_ever_published":false},"categories":[1497],"tags":[],"class_list":["post-16597","post","type-post","status-publish","format-standard","has-post-thumbnail","category-engineering"],"acf":[],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v28.4 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>Optimising Elastic Search Storage for Search Performance<\/title>\n<meta name=\"description\" content=\"This blog describes the optimisation of Elasticsearch indices to improve search performance, sustain peak performance and optimise hardware resources.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.cashfree.com\/blog\/optimising-elasticsearch-storage\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Optimising Elastic Search Storage for Search Performance\" \/>\n<meta property=\"og:description\" content=\"This blog describes the optimisation of Elasticsearch indices to improve search performance, sustain peak performance and optimise hardware resources.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.cashfree.com\/blog\/optimising-elasticsearch-storage\/\" \/>\n<meta property=\"og:site_name\" content=\"Cashfree Payments Blog\" \/>\n<meta property=\"article:published_time\" content=\"2023-03-31T16:15:00+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2023-04-18T08:02:57+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/i0.wp.com\/blogrevamp.cashfree.com\/wp-content\/uploads\/2023\/04\/Report-Indices_Tn_V3.png?fit=2420%2C1606&ssl=1\" \/>\n\t<meta property=\"og:image:width\" content=\"2420\" \/>\n\t<meta property=\"og:image:height\" content=\"1606\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/png\" \/>\n<meta name=\"author\" content=\"Vishal Kumar\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Vishal Kumar\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"7 minutes\" \/>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Optimising Elastic Search Storage for Search Performance","description":"This blog describes the optimisation of Elasticsearch indices to improve search performance, sustain peak performance and optimise hardware resources.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.cashfree.com\/blog\/optimising-elasticsearch-storage\/","og_locale":"en_US","og_type":"article","og_title":"Optimising Elastic Search Storage for Search Performance","og_description":"This blog describes the optimisation of Elasticsearch indices to improve search performance, sustain peak performance and optimise hardware resources.","og_url":"https:\/\/www.cashfree.com\/blog\/optimising-elasticsearch-storage\/","og_site_name":"Cashfree Payments Blog","article_published_time":"2023-03-31T16:15:00+00:00","article_modified_time":"2023-04-18T08:02:57+00:00","og_image":[{"width":2420,"height":1606,"url":"https:\/\/i0.wp.com\/blogrevamp.cashfree.com\/wp-content\/uploads\/2023\/04\/Report-Indices_Tn_V3.png?fit=2420%2C1606&ssl=1","type":"image\/png"}],"author":"Vishal Kumar","twitter_card":"summary_large_image","twitter_misc":{"Written by":"Vishal Kumar","Est. reading time":"7 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.cashfree.com\/blog\/optimising-elasticsearch-storage\/#article","isPartOf":{"@id":"https:\/\/blogrevamp.cashfree.com\/optimising-elasticsearch-storage\/"},"author":{"name":"Vishal Kumar","@id":"https:\/\/blogrevamp.cashfree.com\/#\/schema\/person\/430622ffadb7fe44aeac3745e98f030e"},"headline":"Optimising Elastic Search Storage for Search Performance","datePublished":"2023-03-31T16:15:00+00:00","dateModified":"2023-04-18T08:02:57+00:00","mainEntityOfPage":{"@id":"https:\/\/blogrevamp.cashfree.com\/optimising-elasticsearch-storage\/"},"wordCount":1233,"commentCount":0,"image":{"@id":"https:\/\/www.cashfree.com\/blog\/optimising-elasticsearch-storage\/#primaryimage"},"thumbnailUrl":"https:\/\/i0.wp.com\/blogrevamp.cashfree.com\/wp-content\/uploads\/2023\/04\/Report-Indices_Tn_V3.png?fit=2420%2C1606&ssl=1","articleSection":["Engineering"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/www.cashfree.com\/blog\/optimising-elasticsearch-storage\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/blogrevamp.cashfree.com\/optimising-elasticsearch-storage\/","url":"https:\/\/www.cashfree.com\/blog\/optimising-elasticsearch-storage\/","name":"Optimising Elastic Search Storage for Search Performance","isPartOf":{"@id":"https:\/\/blogrevamp.cashfree.com\/#website"},"primaryImageOfPage":{"@id":"https:\/\/www.cashfree.com\/blog\/optimising-elasticsearch-storage\/#primaryimage"},"image":{"@id":"https:\/\/www.cashfree.com\/blog\/optimising-elasticsearch-storage\/#primaryimage"},"thumbnailUrl":"https:\/\/i0.wp.com\/blogrevamp.cashfree.com\/wp-content\/uploads\/2023\/04\/Report-Indices_Tn_V3.png?fit=2420%2C1606&ssl=1","datePublished":"2023-03-31T16:15:00+00:00","dateModified":"2023-04-18T08:02:57+00:00","author":{"@id":"https:\/\/blogrevamp.cashfree.com\/#\/schema\/person\/430622ffadb7fe44aeac3745e98f030e"},"description":"This blog describes the optimisation of Elasticsearch indices to improve search performance, sustain peak performance and optimise hardware resources.","breadcrumb":{"@id":"https:\/\/www.cashfree.com\/blog\/optimising-elasticsearch-storage\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.cashfree.com\/blog\/optimising-elasticsearch-storage\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.cashfree.com\/blog\/optimising-elasticsearch-storage\/#primaryimage","url":"https:\/\/i0.wp.com\/blogrevamp.cashfree.com\/wp-content\/uploads\/2023\/04\/Report-Indices_Tn_V3.png?fit=2420%2C1606&ssl=1","contentUrl":"https:\/\/i0.wp.com\/blogrevamp.cashfree.com\/wp-content\/uploads\/2023\/04\/Report-Indices_Tn_V3.png?fit=2420%2C1606&ssl=1","width":2420,"height":1606,"caption":"Optimising ElasticSearch Storage for Search Performance"},{"@type":"BreadcrumbList","@id":"https:\/\/www.cashfree.com\/blog\/optimising-elasticsearch-storage\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/blogrevamp.cashfree.com\/"},{"@type":"ListItem","position":2,"name":"Engineering","item":"https:\/\/blogrevamp.cashfree.com\/category\/engineering\/"},{"@type":"ListItem","position":3,"name":"Optimising Elastic Search Storage for Search Performance"}]},{"@type":"WebSite","@id":"https:\/\/blogrevamp.cashfree.com\/#website","url":"https:\/\/blogrevamp.cashfree.com\/","name":"Cashfree Payments Blog","description":"Cashfree Payments- Payment Gateway for India","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/blogrevamp.cashfree.com\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Person","@id":"https:\/\/blogrevamp.cashfree.com\/#\/schema\/person\/430622ffadb7fe44aeac3745e98f030e","name":"Vishal Kumar","url":"https:\/\/blogrevamp.cashfree.com\/author\/vishal-kumar\/"}]}},"jetpack_sharing_enabled":true,"jetpack_shortlink":"https:\/\/wp.me\/p9MjXo-4jH","jetpack_likes_enabled":false,"jetpack_featured_media_url":"https:\/\/i0.wp.com\/blogrevamp.cashfree.com\/wp-content\/uploads\/2023\/04\/Report-Indices_Tn_V3.png?fit=2420%2C1606&ssl=1","_links":{"self":[{"href":"https:\/\/blogrevamp.cashfree.com\/wp-json\/wp\/v2\/posts\/16597","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blogrevamp.cashfree.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blogrevamp.cashfree.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blogrevamp.cashfree.com\/wp-json\/wp\/v2\/users\/73"}],"replies":[{"embeddable":true,"href":"https:\/\/blogrevamp.cashfree.com\/wp-json\/wp\/v2\/comments?post=16597"}],"version-history":[{"count":9,"href":"https:\/\/blogrevamp.cashfree.com\/wp-json\/wp\/v2\/posts\/16597\/revisions"}],"predecessor-version":[{"id":17000,"href":"https:\/\/blogrevamp.cashfree.com\/wp-json\/wp\/v2\/posts\/16597\/revisions\/17000"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/blogrevamp.cashfree.com\/wp-json\/wp\/v2\/media\/16616"}],"wp:attachment":[{"href":"https:\/\/blogrevamp.cashfree.com\/wp-json\/wp\/v2\/media?parent=16597"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blogrevamp.cashfree.com\/wp-json\/wp\/v2\/categories?post=16597"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blogrevamp.cashfree.com\/wp-json\/wp\/v2\/tags?post=16597"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}