> For the complete documentation index, see [llms.txt](https://training.onedoggo.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://training.onedoggo.com/tech-sharing/gong-zuo-fang/hwdc2024/prepare-elasticsearch-environment.md).

# Elasticsearch 環境準備

### 工作坊環境準備

* Elasticsearch 8.15 以上版本
  * 推薦：在 [Elastic Cloud](https://cloud.elastic.co) 使用 Email 註冊即可取得 14 天試用的免費環境，不用綁信用卡!
  * 自行架設：確保版本一定要在 8.15.0 以上，並且是乾淨的環境，單純參與工作坊使用。

    > 工作坊進行中，無法替大家解決各種自行架設造成的環境問題，因此不建議使用自行架設，若是要使用自行架設的環境，請確認自己對於 Elasticsearch 足夠熟悉能排除障礙。
* 這次的操作會使用到 [Google Colab](https://colab.research.google.com/drive/1vYvop3r9IjOpSwYJguVzBjEbqeTyRSRn?usp=sharing)
  * 需要登入你的 Google 帳號，並且依以下教學複製工作坊要使用的 Python Notebook 到你的 Google Drive 當中。

### 1. 準備 Elasticsearch 環境

依照不同的環境，你需要完成以下的任務

使用 Elastic Cloud：

* :white\_large\_square: 從 Elastic Cloud 取得 `Cloud ID`
* :white\_large\_square: 安裝 Elasticsearch Analysis ICU Plugin 以及增加 Machine Learning Instance (重新啟動集群需要 5 分鐘)
* :white\_large\_square: 在 Kibana 建立 API Key

自行架設的 Elasticsearch：

* :white\_large\_square: 安裝 Elasticsearch Analysis ICU Plugin
* :white\_large\_square: 若有啟用 Security，準備好能存取 Elasticsearch 的使用者帳號密碼

#### 1.1 Elastic Cloud 版本的環境準備

**a. 註冊 Elastic Cloud**

![image](https://hackmd.io/_uploads/S1ZAKtxT0.png)

![image](https://hackmd.io/_uploads/rJXjqtx6C.png)

![image](https://hackmd.io/_uploads/SyV_cYlTA.png)

收 Email 確認信。

![image](https://hackmd.io/_uploads/r1vJjKep0.png)

驗證並重新登入後，進入設定流程。

![image](https://hackmd.io/_uploads/BkRZotea0.png)

可以選 Search (非必要)

![image](https://hackmd.io/_uploads/HkHIoKxa0.png)

可以考慮選 Google Cloud Taiwan 的 Region，或許會比較快一點 (非必要)

![image](https://hackmd.io/_uploads/ryCDjtxaR.png)

:::info 點選 Launch 之後，大約要等 3\~5 分鐘，等待 Elasticsearch Cluster 建立。 :::

最後完成時，你會看到下面這樣的畫面，這已經是進入 Kibana 的畫面了。

![image](https://hackmd.io/_uploads/SyhgaYg60.png)

若是要進入

![image](https://hackmd.io/_uploads/By1ZAFgTR.png)

**b. 取得 Elastic Cloud ID**

![image](https://hackmd.io/_uploads/SkQmaz33C.png)

**c. 安裝 ICU Analysis Plugin**

![image](https://hackmd.io/_uploads/ryF_ApFhA.png)

![image](https://hackmd.io/_uploads/rkSJyCKnC.png)

:::warning 第 5 步到第 6 步之中，多增加新增 Machine Learning Instance

* 為了之後試用 ESRE (Elasticsearch Relevance Engine) 功能 :::

![image](https://hackmd.io/_uploads/SybrsxlpA.png)

:::info 試用版的 Machine Learning Instance 的配置，可以增加到 4 GB RAM (非必要，只是可以跑快一些) :::

![image](https://hackmd.io/_uploads/SJ5Hhlgp0.png)

![image](https://hackmd.io/_uploads/HJYQJRt2A.png)

![image](https://hackmd.io/_uploads/SyHDyRF30.png)

:::warning Confirm 之後，大約要等 5 分鐘的時間，讓 Elasticsearch Cluster Rolling update. :::

**d. 建立 API Key**

1. 在 Kibana 網頁上方，搜尋 `API Keys`，進入 **Security / API Keys** 頁面。 :::info Kibana 網址在哪? 從 1.1 步驟的畫面上，就可以看到 Kibana 的 Endpoint，可直接點 Open。 :::
2. 點選右上 `Create API Key`。

![image](https://hackmd.io/_uploads/HyH6vaF3C.png)

3.隨便取一個名字，例如 `HWDC2024-demo`，按下 `Create API Key`。

![image](https://hackmd.io/_uploads/S1ecu6Y3A.png)

4. 畫面上會出現 Encoded 的 API Key，將其複製起來保存。

![image](https://hackmd.io/_uploads/rkF2daY3A.png)

#### 1.2 自行安裝 Elasticsearch 版本的環境準備 (Elastic Cloud 版請略過)

**a. 安裝 ICU Analysis Plugin**

在**每個** Elasticsearch 節點執行以下執行，安裝 plugin，安裝完成後重新啟動節點。

```
./bin/elasticsearch-plugin install analysis-icu
```


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://training.onedoggo.com/tech-sharing/gong-zuo-fang/hwdc2024/prepare-elasticsearch-environment.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
