{"id":738,"date":"2021-04-26T11:15:30","date_gmt":"2021-04-26T09:15:30","guid":{"rendered":"https:\/\/www.ume.li\/blog\/?p=738"},"modified":"2021-04-26T12:56:17","modified_gmt":"2021-04-26T10:56:17","slug":"access-your-index-elastic-search-queries","status":"publish","type":"post","link":"https:\/\/www.ume.li\/blog\/2021\/04\/26\/access-your-index-elastic-search-queries\/","title":{"rendered":"Access your index &#8211; Elastic Search queries"},"content":{"rendered":"<p>HCL Component Pack is fully set-up now, you&#8217;re interested what&#8217;s going on in that mysterious elasticsearch part? In CP 6.5 you&#8217;ve been able to access the ElasticSearch data directly through the kibana pod. With CP7 this seems to be gone.<\/p>\n<p>If you really want\/need to access the ElasticSearch environment, you may use the following path on your own risk<\/p>\n<p>Step 1: get the necessary certificates<\/p>\n<pre class=\"brush: bash; title: getSecrets.sh; notranslate\" title=\"getSecrets.sh\">\r\n#!\/bin\/sh\r\n\r\necho &quot;check directory&quot;\r\ncwd=`pwd`\r\nif &#x5B; ! -d &quot;$cwd\/certs&quot; ]; then\r\n mkdir -p $cwd\/certs\r\nfi\r\nversion='elasticsearch-7-secret'\r\n#version='elasticsearch-secret'\r\necho &quot;extract certificates&quot;\r\nif &#x5B; ! -f &quot;$cwd\/certs\/elasticsearch-healthcheck.crt.pem&quot; ]; then\r\n\tkubectl view-secret -n connections $version elasticsearch-healthcheck.crt.pem &gt; $cwd\/certs\/elasticsearch-healthcheck.crt.pem\r\nfi \r\nif &#x5B; ! -f &quot;$cwd\/certs\/elasticsearch-http.crt.pem&quot; ]; then\r\n\tkubectl view-secret -n connections $version elasticsearch-http.crt.pem &gt; $cwd\/certs\/elasticsearch-http.crt.pem\r\nfi\r\nif &#x5B; ! -f &quot;$cwd\/certs\/elasticsearch-healthcheck.des3.key&quot; ]; then\r\n\tkubectl view-secret -n connections $version elasticsearch-healthcheck.des3.key &gt; $cwd\/certs\/elasticsearch-healthcheck.des3.key\r\nfi\r\n\r\necho &quot;done&quot;\r\n<\/pre>\n<p>This script requires the <a href=\"https:\/\/krew.sigs.k8s.io\/\" title=\"kubectl krew plugins\" rel=\"noopener\" target=\"_blank\">kubectl krew plugins<\/a> installed in your kubectl client.<br \/>\nRun this on your master or a client which has kubectl and the krew plugin installed to get the secrets. <\/p>\n<p>Then you could use the following script as an example:<\/p>\n<pre class=\"brush: bash; title: sendRequest.sh; notranslate\" title=\"sendRequest.sh\">\r\n#!\/bin\/bash\r\n# An util script so that you can interact with es like what official site suggested:\r\n# for additional usage, if you need to do much more complicated operation, pls\r\n# refer to offcial site:\r\n# https:\/\/www.elastic.co\/\r\n\r\n\r\nset -o errexit\r\nset -o pipefail\r\nset -o nounset\r\n\r\n# the directory that all cert placed\r\n# change this to your cert directory.\r\ncert_dir=.\/certs\r\nHOST=`hostname`\r\nURL_base=&quot;https:\/\/localhost:30098&quot;\r\n#CP6.5:\r\n#URL_base=&quot;https:\/\/localhost:30099&quot;\r\n#CP6.5: KEY_PASS=`kubectl view-secret -n connections elasticsearch-secret elasticsearch-key-password.txt`\r\n\r\nKEY_PASS=`kubectl view-secret -n connections elasticsearch-7-secret elasticsearch-key-password.txt`\r\n\r\necho &quot;&#x5B;$KEY_PASS]&quot;\r\nif &#x5B; &quot;${1:-}&quot; = &quot;&quot; ] || &#x5B; &quot;${2:-}&quot; = &quot;&quot; ]; then\r\n  echo &quot;usage: sendRequest.sh   param_method param_url &#x5B;additional param]&quot;\r\n  echo &quot;Request is send to es client(coordinating node) by default. add param&quot;\r\n  echo &quot;to send request to es master node&quot;\r\n  echo &quot;refer: https:\/\/www.elastic.co\/guide\/en\/elasticsearch\/reference\/current\/modules-node.html&quot;\r\n  exit 107\r\nfi\r\n\r\n# save the HTTPS METHOD.\r\n_method=$1\r\n# and then shfit this argument.\r\n# since we need to pass the rest args to curl command unchanged.\r\nshift 1\r\n\r\n# turn off expansion to avoid asterisk becoming current directory\r\nset -f\r\n# please ensure those\r\n#   cert, password, key, cacert\r\n# are at the right location.\r\nresponse_text=$(curl \\\r\n   --insecure \\\r\n   --cert $cert_dir\/elasticsearch-healthcheck.crt.pem:${KEY_PASS} \\\r\n   --key  $cert_dir\/elasticsearch-healthcheck.des3.key \\\r\n   --cacert $cert_dir\/elasticsearch-http.crt.pem \\\r\n   -X${_method} \\\r\n   ${URL_base}&quot;$@&quot;)\r\n\r\n# echo to return to caller.\r\necho ${response_text}\r\n# turn expansion back to 'on'\r\nset +f\r\n<\/pre>\n<p>Now you can use it like this<\/p>\n<pre class=\"brush: bash; title: example:; notranslate\" title=\"example:\">\r\n.\/sendRequest.sh GET \/_cat\/indices &gt; indices.txt\r\n<\/pre>\n<p>Disclaimer: use at your own risk<\/p>\n","protected":false},"excerpt":{"rendered":"<p>HCL Component Pack is fully set-up now, you&#8217;re interested what&#8217;s going on in that mysterious elasticsearch part? In CP 6.5<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[62,54,23],"tags":[],"class_list":["post-738","post","type-post","status-publish","format-standard","hentry","category-62","category-component-pack","category-connections"],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/www.ume.li\/blog\/wp-json\/wp\/v2\/posts\/738","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.ume.li\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.ume.li\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.ume.li\/blog\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.ume.li\/blog\/wp-json\/wp\/v2\/comments?post=738"}],"version-history":[{"count":5,"href":"https:\/\/www.ume.li\/blog\/wp-json\/wp\/v2\/posts\/738\/revisions"}],"predecessor-version":[{"id":743,"href":"https:\/\/www.ume.li\/blog\/wp-json\/wp\/v2\/posts\/738\/revisions\/743"}],"wp:attachment":[{"href":"https:\/\/www.ume.li\/blog\/wp-json\/wp\/v2\/media?parent=738"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.ume.li\/blog\/wp-json\/wp\/v2\/categories?post=738"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.ume.li\/blog\/wp-json\/wp\/v2\/tags?post=738"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}