0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

OpenSearch Dashboards Query Language (DQL) チートシート

Last updated at Posted at 2025-04-10

OpenSearch Dashboards Query Language (DQL) チートシート

基本検索

機能 DQL構文 説明/例
単一ターム検索 error error という単語を含むドキュメントを検索します (デフォルトフィールドまたは全フィールド)。
複数ターム検索 (OR) error warning error または warning を含むドキュメントを検索します (単語間のデフォルトはOR結合)。
完全一致フレーズ検索 "system down" system down という連続したフレーズを含むドキュメントを検索します。

フィールド指定検索

機能 DQL構文 説明/例
特定フィールド検索 status: error status フィールドの値が error であるドキュメントを検索します。
フィールド存在確認 user_id:* user_id フィールドが存在するドキュメントを検索します。
スペースを含むフィールド名 http*host: "example.com" http host のようなスペースを含むフィールド名 (ワイルドカード使用) で "example.com" を検索します。

ワイルドカード (*)

* は0文字以上の任意の文字列にマッチします。単一文字ワイルドカード (?) はサポートされません。

機能 DQL構文 説明/例
ターム内ワイルドカード host: server* host フィールドで server から始まる値 (例: server1, server-eu) を含むドキュメントを検索します。
path: *.log path フィールドで .log で終わる値を含むドキュメントを検索します。
フィールド名ワイルドカード log*level: error log で始まり level で終わるフィールド名 (例: log_level) の値が error のドキュメントを検索します。
非対応 "error * occurred" フレーズ検索内でのワイルドカードはサポートされません。

範囲検索

機能 DQL構文 説明/例
数値範囲 (含む) response_time >= 500 and response_time <= 1000 response_time が 500 以上 1000 以下のドキュメントを検索します。
数値範囲 (含まない) cpu_usage > 0.9 cpu_usage が 0.9 より大きいドキュメントを検索します。
日付範囲 timestamp >= "2023-10-26T10:00:00Z" and timestamp < "2023-10-26T11:00:00Z" 指定されたISO 8601形式の日時範囲内のドキュメントを検索します。
値の否定 not status: 200 status200 でないドキュメント、または status フィールドを持たないドキュメントを検索します。
値の否定 (フィールド存在) status:* and not status: 200 status フィールドが存在し、かつその値が 200 でないドキュメントを検索します。
非対応 {500 TO 1000} Luceneのような排他的範囲構文 ({}) はサポートされません。

ブール演算子

大文字・小文字は区別されません (ANDand は同じ意味)。

機能 DQL構文 説明/例
AND level: error and service: auth levelerror であり、かつ serviceauth であるドキュメントを検索します。
OR (デフォルト) level: error or level: warning levelerror である、または levelwarning であるドキュメントを検索します。
error warning (フィールド指定なし) error または warning を含むドキュメント (デフォルトOR)。
NOT not country: US countryUS でないドキュメント、または country フィールドを持たないドキュメントを検索します。
level: error and not service: test levelerror であり、かつ servicetest でないドキュメントを検索します。
演算子の優先順位 NOT > AND > OR a or b and not ca or (b and (not c)) と解釈されます。
グループ化 (括弧) (service: api or service: web) and level: error 括弧内の式 (service: api or service: web) を優先的に評価します。

特殊文字とエスケープ

機能 DQL構文 説明/例
予約文字 \, (, ), :, <, >, ", * これらの文字自体を検索値として使いたい場合は、バックスラッシュ \ でエスケープします。
エスケープ path: "C:\\Program Files\\App" \ を文字として検索するために \\ とエスケープします。
product_id: "item\*123" * を文字として検索するために \* とエスケープします。

ネスト/オブジェクト

機能 DQL構文 説明/例
オブジェクトフィールド user.id: 123 user オブジェクト内の id フィールドが 123 であるドキュメントを検索します (ドット記法)。
ネストされたフィールド comments: {author: "John Doe"} comments (nested型) 内のオブジェクトで author"John Doe" であるものを含むドキュメントを検索。
ネスト内複数条件 (AND) comments: {author: "John Doe" and rating >= 4} comments 内の 同一 オブジェクトが author: "John Doe" かつ rating >= 4 を満たすドキュメント。
ネストと通常フィールド comments: {author: "John Doe"} and status: approved comments 内に author: "John Doe" を含むオブジェクトがあり、かつ statusapproved のドキュメント。
二重ネスト items: {variants: {color: red}} items (nested) 内の variants (nested) 内のオブジェクトで colorred のものを検索。

その他

機能 DQL構文 説明/例
空白の無視 status: errorstatus:error は同じ意味です。 フィールド名と値の間、演算子の前後の空白は基本的に無視されます。
非対応機能 正規表現, ファジー検索 (~), 近接検索 (~N), ブースティング (^), 必須/禁止演算子 (+, -) はDQLではサポートされていません (これらはLucene構文の機能です)。
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?