{"id":10857,"date":"2024-04-03T21:32:18","date_gmt":"2024-04-04T02:32:18","guid":{"rendered":"https:\/\/www.rushworth.us\/lisa\/?p=10857"},"modified":"2024-04-03T21:32:19","modified_gmt":"2024-04-04T02:32:19","slug":"elasticsearch-to-opensearch-migration-creating-roles","status":"publish","type":"post","link":"https:\/\/www.rushworth.us\/lisa\/?p=10857","title":{"rendered":"ElasticSearch to OpenSearch Migration: Creating Roles"},"content":{"rendered":"\n<p>To create the roles, use the ElasticSearch API to get the existing role definitions, remove a few attributes I don&#8217;t want to set (reserved, static, hidden), and create the corresponding role in OpenSearch. I skip all of the reserved roles.<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: python; title: ; notranslate\" title=\"\">\nimport requests\nfrom requests.auth import HTTPBasicAuth\n\nf = open(&quot;results-roles.txt&quot;, &quot;a&quot;)\n\nobjGetRoleRequest = requests.get(f&quot;https:\/\/elasticsearch.example.com:9200\/_opendistro\/_security\/api\/roles&quot;, auth = HTTPBasicAuth(&#039;something&#039;, &#039;something&#039;), verify=False)\ndictRoleInfo = objGetRoleRequest.json()\nfor item in dictRoleInfo.items():\n        if item&#x5B;1].get(&#039;reserved&#039;) is False:\n                print(item)\n                print(&quot;\\n&quot;)\n                dictRoleDefinition = dict(item&#x5B;1])\n                dictRoleDefinition.pop(&#039;reserved&#039;)\n                dictRoleDefinition.pop(&#039;static&#039;)\n                dictRoleDefinition.pop(&#039;hidden&#039;)\n                r = requests.put(f&quot;https:\/\/opensearch.example.com:9200\/_plugins\/_security\/api\/roles\/{item&#x5B;0]}&quot;, json=dictRoleDefinition, auth = HTTPBasicAuth(&#039;something&#039;, &#039;something&#039;), verify=False)\n                print(r.json())\n\n                if r.status_code == 200:\n                        print(f&quot;{item&#x5B;0]}\\t{r.status_code}\\t{r.json()}\\n&quot;)\n                        f.write(f&quot;{item&#x5B;0]}\\t{r.status_code}\\t{r.json()}\\n&quot;)\n                else:\n                        print(f&quot;HTTP Error: {r.status_code} on web call&quot;)\n                        print(f&quot;{item&#x5B;0]}\\t{r.status_code}\\t{r.json()}\\n&quot;)\n                        f.write(f&quot;{item&#x5B;0]}\\t{r.status_code}\\t{r.json()}\\n&quot;)\nf.close()\n<\/pre><\/div>","protected":false},"excerpt":{"rendered":"<p>To create the roles, use the ElasticSearch API to get the existing role definitions, remove a few attributes I don&#8217;t want to set (reserved, static, hidden), and create the corresponding role in OpenSearch. I skip all of the reserved roles.<\/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-10857","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\/10857","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=10857"}],"version-history":[{"count":1,"href":"https:\/\/www.rushworth.us\/lisa\/index.php?rest_route=\/wp\/v2\/posts\/10857\/revisions"}],"predecessor-version":[{"id":10858,"href":"https:\/\/www.rushworth.us\/lisa\/index.php?rest_route=\/wp\/v2\/posts\/10857\/revisions\/10858"}],"wp:attachment":[{"href":"https:\/\/www.rushworth.us\/lisa\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=10857"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.rushworth.us\/lisa\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=10857"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.rushworth.us\/lisa\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=10857"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}