喬叔的 Elastic Stack 專業教育訓練
  • 喬叔的 Elastic Stack 專業教育訓練
  • 🧑關於喬叔 (Joe Wu)
  • Elastic 課程公開班
    • 🎯Elasticsearch 基礎實務班
      • 💯學員課後回饋
    • 🆕Elasticsearch 進階運維班
      • 💯學員課後回饋
    • Elasticsearch 進階開發班
    • Elastic Stack 基礎實務班
    • Elastic Observability 基礎實務班
    • 📩課程許願池
  • 技術分享
    • 📗喬叔帶你上手 Elastic Stack
      • 前言
      • Elastic Cloud 如何建立 Deployment
        • ES Node 的種類
        • 配置的選擇
      • Index 建立前你該知道的
        • ES Index 如何被建立
        • ES 的超前佈署 - Dynamic Mapping
        • ES 的超前佈署 - Index Template
        • ES Index 的別名 (Alias)
        • 管理你的 Index - Kibana Index
      • 管理 Index 的 Best Practices
        • Shard 的數量與 Rollover & Shrink API
        • 三溫暖架構 - Hot Warm Cold Architecture
        • Index Lifecycle Management (ILM)
        • Rollup
        • Transform
        • Snapshot Lifecycle Management (SLM)
        • 總結
      • Elastic Cloud 比免費版還多的功能
        • Elastic Stack 的方案比較與銷售方式
        • Centralized Beats Management
        • Centralized Pipeline Management
        • Watcher
        • Elasticsearch Token Service
        • Multi-stack monitoring & Automatic stack issue alerts
      • 向 App Search 學習怎麼用 Elasticsearch
        • 揭開 App Search 的面紗
        • Engine 的 Index Settings 篇
        • Engine 的 Mapping 篇
        • Engine 的 Search 基礎剖析篇
        • Engine 的 Search 進階剖析篇
      • Elasticsearch 的優化技巧
        • Indexing 索引效能優化
        • Searching 搜尋效能優化
        • Index 的儲存空間最佳化
        • Shard 的最佳化管理
      • 完賽心得
    • 📘喬叔帶你上手 Elastic Stack - 探索與實踐 Observability 系列
      • 前言 & 淺談 Observability
      • Elastic 的 Observability 解決方案
      • Uptime - 掌握系統的生命徵象
        • 我們要觀測的生命徵象是什麼?
        • 使用 Heartbeat 收集系統生命徵象數據
        • 透過 Kibana 觀看心電圖及設定警報
        • 使用合成監控 (Synthetics Monitor) 從使用者情境驗證服務的運作狀態
      • Metrics - 觀察系統的健康指標
        • Metrics 與 Metricbeat 的基本介紹
        • 使用 Metricbeat 掌握 Elastic Stack 的健康狀態
        • 使用 Metricbeat 掌握 Infrastructure 的健康狀態 Host 篇
        • 使用 Metricbeat 掌握 Infrastructure 的健康狀態 Docker 篇
        • 使用 Metricbeat 掌握 Infrastructure 的健康狀態 Kubernetes 篇
        • 使用 Metricbeat 掌握 Infrastructure 的健康狀態 AWS 篇
      • Logs - 挖掘系統內部發生的狀況
        • Logs 與 Filebeat 的基本介紹
        • 使用 Filebeat 應該要了解的設計細節與原理
        • 透過 Filebeat 收集 Elastic Stack 中各種服務的細節資訊
        • 透過 Filebeat 收集 Infrastructure 中各種服務的細節資訊
      • Traces - 觀察應用程式的效能瓶頸
        • Elastic APM 基本介紹
        • 使用 APM-Integratoin-Testing 建立 Elastic APM 的模擬環境
        • 如何在 Kibana 使用 APM UI
        • 使用 APM Server 來收集 APM 數據
        • 透過 APM Agents 收集並傳送後端服務運作的記錄
        • 透過真實使用者監控 (RUM, Real User Monitoring) 來改善使用者體驗
      • 建立結構化的 Log
        • Elastic Common Schema 結構化 Log 的規範
        • Elasticsearch Ingest Pipeline 資料 Index 前的轉換好幫手
          • 基本介紹
          • 各種常用的 Processor
          • Enrich 資料與例外處理
      • 有效的使用 Observability 的資料
        • 透過 Machine Learning 發現異常的問題
        • 使用 Kibana Alerts 主動通知異常狀況
        • 資料的生命週期管理
        • 使用 Elastic Observability 追縱及觀察問題的心得
      • 完賽心得
    • 😀Elasticsearch 技術分享小品
      • 🤖Elastic 與 AI
        • Elasticsearch Inference API 讓我們直接在 ES 裡運用 OpenAI Completion API
    • 🎥線上分享
      • 喬叔 Elasticsearch Index 管理與效能優化技巧
      • Elastic Certification 認證經驗分享
    • 🛠️workshop
      • 如何在 Elasticsearch 實現敏捷的資料建模與管理 @ DevOpsDays 2023
        • 工作坊實作內容
      • Elastic Observability 實作體驗坊 @ DevOpsDays 2022
        • 行前準備
        • 工作坊實作內容
      • 當 Elasticsearch 搜尋引擎遇上 AI @ HelloWordDevConference 2024
        • 投影片
        • Elasticsearch 環境準備
        • Google Colab 環境準備
        • 工作坊操作說明
        • ElasticSearch Relevance Engine (ESRE)
    • ⬆️Elastic Stack 版本升級記錄
      • 🔍Elasticsearch
  • 其他專業服務
    • 👩‍🎓企業包班 | 企業內訓
    • 👨‍💼顧問服務
    • 🈺專案合作
    • 🧩Elastic 授權代理
  • 相關連結
    • Facebook 粉絲頁
Powered by GitBook
On this page
  • 前言
  • 進入此章節的先備知識
  • 此章節的重點學習
  • App Search 簡介
  • 揭開 App Search 的面紗
  • App Search System Indices
  • 建立 Engine
  • Import document
  • Query Indexed Document
  • Update Engine Schema
  • 小結
  • 參考資料
  1. 技術分享
  2. 喬叔帶你上手 Elastic Stack
  3. 向 App Search 學習怎麼用 Elasticsearch

揭開 App Search 的面紗

Previous向 App Search 學習怎麼用 ElasticsearchNextEngine 的 Index Settings 篇

Last updated 2 years ago

前言

這個系列我們針對 Elastic Stack 產品系列 Enterprise Search 中的 App Search 來進行剖析,看看 App Search 是如何使用 Elasticsearch ,從這個探索的過程中,讓我們期待從中學習一些 App Search 值得我們參考的使用方式。

進入此章節的先備知識

  • Elasticsearch 的基礎使用知識

  • App Search 的基礎使用知識

此章節的重點學習

  • 初探 App Search 是如何把 Elasticsearch 當成 NoSQL Database 來使用。


App Search 簡介

我這篇不會針對 App Search 有太多細節介紹,剛好這次鐵人賽我參加的團隊隊長 - 少女人妻 ,他這次的主題 就有蠻詳細的 App Search 介紹,所以對於 App Search 還不太熟悉的朋,推薦大家去拜讀她的文章。

img

簡單來說,App Search 是提供了一個 Out of Box Experience (OOBE) 使用 Elasticsearch 搜尋服務的產品,讓使用端以 API 的方式將文件透過 App Search 存入,並且提供 API 能將文件搜尋出來,你不需要知道怎麼使用 Elasticsearch、如何下 Query、如何優化 Query 的方式,這些 App Search 都提供了一套預設配置,讓你基本上可以達到一定好用的程度。

而 App Search 底層不僅是使用 Elasticsearch 當作 Document 的 Index engine,同時也把 Elasticsearch 當作 NoSQL database 來存放 App Search 這個應用程式所需要儲存的資料或是設定值。

揭開 App Search 的面紗

App Search System Indices

當我們使用 Elastic Cloud 並啟用 Enterprise Search 、或是自己架設 App Search 並將他指向某一個 Elasticsearch Cluster 時,我們從 Elasticsearch 的 Index 中,可以發現有許多 .ent-search 開頭的 Indices,如下圖:

這圖是使用 ElasticSearch Head chrome plugin 的截圖,因為他的排版較適合列出大量的 index name

這些 Index 許多可以從名字猜出用途,另外這邊列幾個比較重要的:

  • 包含 *-app_search_* 字眼的:這些用途蠻明的,包含 app search settings, accounts, api_tokens...等,就是存放 App Search 一些 application data 用的。

  • .ent-search-actastic-engine_document_backends_v2: 這個是存放了 backend level 會用到的 engines 的 meta 資料,有幾個 engines 就有幾筆 document,只有簡單的 engine 建立時間、engine id、是否可讀寫的狀態。

  • .ent.search-actastic-engines_v9: 這裡存放的是定義每個 engines 的詳細資料。

  • .ent-search-engine-*: 這個會是每個 engines 產生一個 index,裡面存放的就會是這個 engine 裡面的所有 document。

建立 Engine

一開始我們 .ent-search-actastic-engines_v9 index 會是空的,所以我們透過 App Search UI 來建立一個 Engine。

建立完成後,我們查詢 .ent-search-actastic-engines_v9

GET .ent-search-actastic-engines_v9/_search

看看裡面有什麼:

{
  "took" : 1,
  "timed_out" : false,
  "_shards" : {
    "total" : 1,
    "successful" : 1,
    "skipped" : 0,
    "failed" : 0
  },
  "hits" : {
    "total" : {
      "value" : 1,
      "relation" : "eq"
    },
    "max_score" : 1.0,
    "hits" : [
      {
        "_index" : ".ent-search-actastic-engines_v9",
        "_type" : "_doc",
        "_id" : "5f7cc70189dec99f64b0dd35",
        "_score" : 1.0,
        "_source" : {
          "id" : "5f7cc70189dec99f64b0dd35",
          "created_at" : "2020-10-06T19:35:29Z",
          "updated_at" : "2020-10-06T19:42:15Z",
          "type_" : "Engine::IndexedEngine",
          "account_id" : null,
          "cluster_id" : "5f5c740c481a32491fcccccd",
          "key" : "JM-N2oBNNbieV2QXRrh-",
          "loco_moco_account_id" : "5f5c740d481a32491fccccd0",
          "managing_application_id" : null,
          "slug" : "joe-test",
          "name" : "joe-test",
          "api_based" : true,
          "last_touched_at" : null,
          "stub" : false,
          "demo" : false,
          "sample" : false,
          "meta_data" : { },
          "source" : null,
          "queued_for_deletion" : null,
          "frito_pie_content_source_id" : null,
          "page_limit" : null,
          "document_count" : 1,
          "moving" : false,
          "deaggregation_requested" : false,
          "index_settings_override" : { },
          "index_create_settings_override" : { },
          "query_boosted_documents_enabled" : false,
          "query_boosted_queries_enabled_override" : false,
          "language" : "zh",
          "source_engine_ids" : [ ]
        }
      }
    ]
  }
}

這個就是我們的 Engine 的資料,包含了 engine 名稱 joe-test 、我選擇的語系 zh …等資訊,另外 5f7cc70189dec99f64b0dd35 這個是我們的 Engine Id,這個要記起來,之後會用到。

Import document

光是建立 Engine,文件沒有放進去的話,還不會產生對應的 Index ,所以我們再次透過 App Search UI 來新增一份文件。

以下是我從預設的範例精簡後的版本:

[
  {
    "id": "park_rocky-mountain",
    "title": "Rocky Mountain",
    "description": "Bisected north to south by the Continental Divide, this portion of the Rockies has ecosystems varying from over 150 riparian lakes to montane and subalpine forests to treeless alpine tundra. Wildlife including mule deer, bighorn sheep, black bears, and cougars inhabit its igneous mountains and glacial valleys. Longs Peak, a classic Colorado fourteener, and the scenic Bear Lake are popular destinations, as well as the historic Trail Ridge Road, which reaches an elevation of more than 12,000 feet (3,700 m).",
    "visitors": 4517585,
    "location": "40.4,-105.58",
    "date": "1915-01-26T06:00:00Z"
  }
]

透過 UI Import 進 App Search 後,會看到 5 個欄位被加入說 Engine's schema 了。

這時我們去查看 Index

GET _cat/indices?v&index=*engine*

會發現多了一個 .ent-search-engine-5f7cc70189dec99f64b0dd35 的 Index ,也就是我們這個 Engine 的 Index ,並且 docs.count 顯示裡面有一份文件。

Query Indexed Document

我們先簡單的查看這個裡面的 Document 長什麼樣子:

GET .ent-search-engine-5f7cc70189dec99f64b0dd35/_search

以下是回傳的結果:

{
  "took" : 4,
  "timed_out" : false,
  "_shards" : {
    "total" : 2,
    "successful" : 2,
    "skipped" : 0,
    "failed" : 0
  },
  "hits" : {
    "total" : {
      "value" : 1,
      "relation" : "eq"
    },
    "max_score" : 1.0,
    "hits" : [
      {
        "_index" : ".ent-search-engine-5f7cc70189dec99f64b0dd35",
        "_type" : "_doc",
        "_id" : "5f7cc89489dec9fc34b0dd38",
        "_score" : 1.0,
        "_source" : {
          "title$string" : "Rocky Mountain",
          "description$string" : "Bisected north to south by the Continental Divide, this portion of the Rockies has ecosystems varying from over 150 riparian lakes to montane and subalpine forests to treeless alpine tundra. Wildlife including mule deer, bighorn sheep, black bears, and cougars inhabit its igneous mountains and glacial valleys. Longs Peak, a classic Colorado fourteener, and the scenic Bear Lake are popular destinations, as well as the historic Trail Ridge Road, which reaches an elevation of more than 12,000 feet (3,700 m).",
          "visitors$string" : "4517585",
          "location$string" : "40.4,-105.58",
          "date$string" : "1915-01-26T06:00:00Z",
          "id" : "5f7cc89489dec9fc34b0dd38",
          "external_id" : "park_rocky-mountain",
          "engine_id" : "5f7cc70189dec99f64b0dd35",
          "__st_text_summary" : "Rocky Mountain Bisected north to south by the Continental Divide, this portion of the Rockies has ecosystems varying from over 150 riparian lakes to montane and subalpine forests to treeless alpine tundra. Wildlife including mule deer, bighorn sheep, black bears, and cougars inhabit its igneous mountains and glacial valleys. Longs Peak, a classic Colorado fourteener, and the scenic Bear Lake are popular destinations, as well as the historic Trail Ridge Road, which reaches an elevation of more than 12,000 feet (3,700 m). 4517585 40.4,-105.58 1915-01-26T06:00:00Z",
          "__st_expires_after" : null
        }
      }
    ]
  }
}

我們可以看到,這個 document 有幾部份:

  • id, engine_id: 這邊都是記錄 engine id。

  • __st_text_summary: 這個欄位把所有值都合併在一起並使用 text 型態來描述。

  • 每個我們定義的欄位名稱,後面都被帶上了他的型態 $string。

這就是 App Search 使用 Elasticsearch 存放的 Document 外觀的長相。

Update Engine Schema

若是我們更新的欄位的型態,再來看看 Document 的變化:

{
  "took" : 256,
  "timed_out" : false,
  "_shards" : {
    "total" : 2,
    "successful" : 2,
    "skipped" : 0,
    "failed" : 0
  },
  "hits" : {
    "total" : {
      "value" : 1,
      "relation" : "eq"
    },
    "max_score" : 1.0,
    "hits" : [
      {
        "_index" : ".ent-search-engine-5f7cc70189dec99f64b0dd35",
        "_type" : "_doc",
        "_id" : "5f7cc89489dec9fc34b0dd38",
        "_score" : 1.0,
        "_source" : {
          "title$string" : "Rocky Mountain",
          "description$string" : "Bisected north to south by the Continental Divide, this portion of the Rockies has ecosystems varying from over 150 riparian lakes to montane and subalpine forests to treeless alpine tundra. Wildlife including mule deer, bighorn sheep, black bears, and cougars inhabit its igneous mountains and glacial valleys. Longs Peak, a classic Colorado fourteener, and the scenic Bear Lake are popular destinations, as well as the historic Trail Ridge Road, which reaches an elevation of more than 12,000 feet (3,700 m).",
          "visitors$float" : 4517585.0,
          "location$location" : "40.4,-105.58",
          "date$date" : "1915-01-26T06:00:00+00:00",
          "id" : "5f7cc89489dec9fc34b0dd38",
          "external_id" : "park_rocky-mountain",
          "engine_id" : "5f7cc70189dec99f64b0dd35",
          "__st_text_summary" : "Rocky Mountain Bisected north to south by the Continental Divide, this portion of the Rockies has ecosystems varying from over 150 riparian lakes to montane and subalpine forests to treeless alpine tundra. Wildlife including mule deer, bighorn sheep, black bears, and cougars inhabit its igneous mountains and glacial valleys. Longs Peak, a classic Colorado fourteener, and the scenic Bear Lake are popular destinations, as well as the historic Trail Ridge Road, which reaches an elevation of more than 12,000 feet (3,700 m). 4517585 40.4,-105.58 1915-01-26T06:00:00Z",
          "__st_expires_after" : null
        }
      }
    ]
  }
}

一但更新 Schema,這些 Document 都會被 re-indexing,並且變成新的 Document,而且改變型態的欄位名稱也都跟著改變了:

  • visitors$string -> visitors$float

  • location$string -> location$location

  • date$string -> date$date

小結

到目前為止,我們了解了 App Search 在建立 Engine 時,是如何使用 Elasticsearch 存放相關的資料,以及 Import 一份文件進入 App Search 他是怎麼存放的,後續的文章將會進一步探索 Index Setting, Mapping...等深入的剖析。

參考資料

(圖片來源:)

app search indexes
image-20201007032436502
image-20201007034222461
image-20201007034849153
image-20201007040635761

📗
Solutions: Elastic App Search 入門
Solutions: Elastic App Search 入門
少女人妻的30天Elastic