{"id":10863,"date":"2024-04-05T21:36:53","date_gmt":"2024-04-06T02:36:53","guid":{"rendered":"https:\/\/www.rushworth.us\/lisa\/?p=10863"},"modified":"2024-04-03T21:41:22","modified_gmt":"2024-04-04T02:41:22","slug":"elasticsearch-to-opensearch-migration-lifecycle-management-policies","status":"publish","type":"post","link":"https:\/\/www.rushworth.us\/lisa\/?p=10863","title":{"rendered":"ElasticSearch to OpenSearch Migration: Lifecycle Management Policies"},"content":{"rendered":"\n<p>Since there are a lot of changes in how lifecycle policies work between ElasticSearch and OpenSearch, the recommendation I&#8217;ve seen is to manually create them &#8230; but it&#8217;s a lot of repetitive typing, so I used a script to create a base policy &#8212; a name with a a hot allocation &#8212; and manually added all of the remaining stages, transitions, and index patterns to which the policy should be applied. <\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: python; title: ; notranslate\" title=\"\">\nimport requests\nfrom requests.auth import HTTPBasicAuth\nimport json\nfrom time import sleep\nfrom datetime import timedelta\n\nf = open(&quot;data-LifecyclePolicies.txt&quot;, &quot;w&quot;)\n\nlistIgnoredILMPolicies = &#x5B;&quot;watch-history-ilm-policy&quot;]\n\n# Get all roles from prod &amp; list users in those roles\nr = requests.get(f&quot;https:\/\/elasticsearch.example.com:9200\/_ilm\/policy&quot;, auth = HTTPBasicAuth(&#039;something&#039;, &#039;something&#039;), verify=False)\n\ndictAllILMPolicies= r.json()\n\nfor item in dictAllILMPolicies.items():\n        if item&#x5B;0] not in listIgnoredILMPolicies:\n                strILMPolicyName = item&#x5B;0]\n                dictILMPolicySettings = item&#x5B;1]\n                iHotDays = None\n                iWarmDays = None\n                iColdDays = None\n                iDeleteDays = None\n                if item&#x5B;1].get(&#039;policy&#039;).get(&#039;phases&#039;).get(&#039;hot&#039;):\n                        iHotDays = (item&#x5B;1].get(&#039;policy&#039;).get(&#039;phases&#039;).get(&#039;hot&#039;).get(&#039;min_age&#039;))\n                if item&#x5B;1].get(&#039;policy&#039;).get(&#039;phases&#039;).get(&#039;warm&#039;):\n                        iWarmDays = (item&#x5B;1].get(&#039;policy&#039;).get(&#039;phases&#039;).get(&#039;warm&#039;).get(&#039;min_age&#039;))\n                if item&#x5B;1].get(&#039;policy&#039;).get(&#039;phases&#039;).get(&#039;cold&#039;):\n                        iColdDays = (item&#x5B;1].get(&#039;policy&#039;).get(&#039;phases&#039;).get(&#039;cold&#039;).get(&#039;min_age&#039;))\n                if item&#x5B;1].get(&#039;policy&#039;).get(&#039;phases&#039;).get(&#039;delete&#039;):\n                        iDeleteDays = (item&#x5B;1].get(&#039;policy&#039;).get(&#039;phases&#039;).get(&#039;delete&#039;).get(&#039;min_age&#039;))\n                print(f&quot;Policy named {strILMPolicyName} has phases:&quot;)\n                print(f&quot;\\tHot {iHotDays}&quot;)\n                print(f&quot;\\tWarm {iWarmDays}&quot;)\n                print(f&quot;\\tCold {iColdDays}&quot;)\n                print(f&quot;\\tDelete {iDeleteDays}&quot;)\n                print(&quot;\\n&quot;)\n\n                f.write(f&quot;Policy named {strILMPolicyName} has phases:\\n&quot;)\n                f.write(f&quot;\\tHot {iHotDays}\\n&quot;)\n                f.write(f&quot;\\tWarm {iWarmDays}\\n&quot;)\n                f.write(f&quot;\\tCold {iColdDays}\\n&quot;)\n                f.write(f&quot;\\tDelete {iDeleteDays}\\n&quot;)\n                f.write(&quot;\\n&quot;)\n                jsonILMPolicyCreation = {\n                                  &quot;policy&quot;: {\n                                    &quot;description&quot;: &quot;Ported from ES7&quot;,\n                                    &quot;default_state&quot;: &quot;hot&quot;,\n                                    &quot;states&quot;: &#x5B;\n                                      {\n                                        &quot;name&quot;: &quot;hot&quot;,\n                                        &quot;actions&quot;: &#x5B;\n                                          {\n                                            &quot;retry&quot;: {\n                                              &quot;count&quot;: 3,\n                                              &quot;backoff&quot;: &quot;exponential&quot;,\n                                              &quot;delay&quot;: &quot;1m&quot;\n                                            },\n                                            &quot;allocation&quot;: {\n                                              &quot;require&quot;: {\n                                                &quot;temp&quot;: &quot;hot&quot;\n                                              },\n                                              &quot;include&quot;: {},\n                                              &quot;exclude&quot;: {},\n                                              &quot;wait_for&quot;: &quot;false&quot;\n                                            }\n                                          }\n                                        ],\n                                        &quot;transitions&quot;: &#x5B;]\n                                      }\n                                    ],\n                                    &quot;ism_template&quot;: &#x5B;]\n                                  }\n                                }\n\n                r2 = requests.put(f&quot;https:\/\/opensearch:9200\/_plugins\/_ism\/policies\/{item&#x5B;0]}&quot;, json=jsonILMPolicyCreation, auth = HTTPBasicAuth(&#039;something&#039;, &#039;something&#039;), verify=False)\n                print(r2.text)\n                print(r2.status_code)\nf.close()\n<\/pre><\/div>","protected":false},"excerpt":{"rendered":"<p>Since there are a lot of changes in how lifecycle policies work between ElasticSearch and OpenSearch, the recommendation I&#8217;ve seen is to manually create them &#8230; but it&#8217;s a lot of repetitive typing, so I used a script to create a base policy &#8212; a name with a a hot allocation &#8212; and manually added &hellip;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1588],"tags":[1590,2001,1740],"class_list":["post-10863","post","type-post","status-publish","format-standard","hentry","category-elk","tag-elasticsearch","tag-elasticsearch-to-opensearch-migration","tag-opensearch"],"_links":{"self":[{"href":"https:\/\/www.rushworth.us\/lisa\/index.php?rest_route=\/wp\/v2\/posts\/10863","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.rushworth.us\/lisa\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.rushworth.us\/lisa\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.rushworth.us\/lisa\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.rushworth.us\/lisa\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=10863"}],"version-history":[{"count":1,"href":"https:\/\/www.rushworth.us\/lisa\/index.php?rest_route=\/wp\/v2\/posts\/10863\/revisions"}],"predecessor-version":[{"id":10864,"href":"https:\/\/www.rushworth.us\/lisa\/index.php?rest_route=\/wp\/v2\/posts\/10863\/revisions\/10864"}],"wp:attachment":[{"href":"https:\/\/www.rushworth.us\/lisa\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=10863"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.rushworth.us\/lisa\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=10863"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.rushworth.us\/lisa\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=10863"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}