本文為英文版的機器翻譯版本,如內容有任何歧義或不一致之處,概以英文版為準。
使用管道處理語言查詢 Amazon OpenSearch 服務資料
管道處理語言 (PPL) 是一種查詢語言,可讓您使用管道 (|
) 語法查詢儲存在 Amazon OpenSearch 服務中的資料。PPL 需要或彈性搜索 7.9 OpenSearch 或更高版本。
注意
本文件提供了適用於 Amazon OpenSearch 服務的 PPL 的簡要概述。如需詳細步驟和完整的命令參考資料,請參閱開放原始碼 OpenSearch 文件中的 PPL
PPL 語法包含以管道字元 (|
) 分隔的命令,資料在其中通過每個管道從左流到右。例如,用來尋找具有 HTTP 403 或 503 錯誤的主機數目、依據主機進行彙總並依影響順序對它們排序的 PPL 語法,如下所示:
source = dashboards_sample_data_logs | where response='403' or response='503' | stats count(request) as request_count by host, response | sort -request_count
若要開始使用,請選擇 OpenSearch 儀表板中的查詢工作台,然後選取 PPL。使用 bulk
操作來索引一些範例資料:
PUT accounts/_bulk?refresh {"index":{"_id":"1"}} {"account_number":1,"balance":39225,"firstname":"Amber","lastname":"Duke","age":32,"gender":"M","address":"880 Holmes Lane","employer":"Pyrami","email":"amberduke@pyrami.com","city":"Brogan","state":"IL"} {"index":{"_id":"6"}} {"account_number":6,"balance":5686,"firstname":"Hattie","lastname":"Bond","age":36,"gender":"M","address":"671 Bristol Street","employer":"Netagy","email":"hattiebond@netagy.com","city":"Dante","state":"TN"} {"index":{"_id":"13"}} {"account_number":13,"balance":32838,"firstname":"Nanette","lastname":"Bates","age":28,"gender":"F","address":"789 Mady Street","employer":"Quility","city":"Nogal","state":"VA"} {"index":{"_id":"18"}} {"account_number":18,"balance":4180,"firstname":"Dale","lastname":"Adams","age":33,"gender":"M","address":"467 Hutchinson Court","email":"daleadams@boink.com","city":"Orick","state":"MD"}
下列範例會對 age
大於 18 的帳戶索引中的文件傳回 firstname
和 lastname
欄位:
search source=accounts | where age > 18 | fields firstname, lastname
id | firstname | lastname |
---|---|---|
0 | Amber | Duke |
1 | Hattie | Bond |
2 | Nanette | Bates |
3 | Dale | Adams |
您可以使用一組完整的唯讀命令,如 search
、where
、fields
、rename
、dedup
、stats
、sort
、eval
、head
、top
以及 rare
。PPL 外掛程式支援所有 SQL 函數,包括數學、三角函數、日期時間、字串、彙總以及進階運算子和表達式。若要進一步了解,請參閱 OpenSearch PPL 參考手冊