@elastic/esql-types

中文文档
4.39.0发布于 2026/11/11Elastic-2.0TypeScriptESM + CJS零依赖构建来源已验证近 30 天下载 39.4万

TypeScript type definitions for the ES|QL AST.

原始使用文档
文档目录5 节
  1. Install
  2. Usage
  3. PromQL types
  4. Key type relationships
  5. Notes

@elastic/esql-types

Shared TypeScript type definitions for the ES|QL and PromQL ASTs. Pure type definitions — no runtime code, no dependencies.

Install

npm install @elastic/esql-types

Usage

import type {
  // Top-level AST
  ESQLAstQueryExpression,
  ESQLAst,

  // Commands
  ESQLCommand,
  ESQLAstHeaderCommand,

  // Expressions
  ESQLFunction,
  ESQLFunctionCallExpression,
  ESQLBinaryExpression,
  ESQLColumn,
  ESQLLiteral,
  ESQLSource,
  ESQLInlineCast,
  ESQLOrderExpression,

  // ... and more

} from '@elastic/esql-types';

PromQL types

import type {
  PromQLAstQueryExpression,
  PromQLAstExpression,
  PromQLFunction,
  PromQLSelector,
  PromQLBinaryExpression,
  PromQLLabel,
} from '@elastic/esql-types';

Key type relationships

ESQLAstQueryExpression          root node — holds commands[]
  ESQLCommand                   a pipeline stage (FROM, WHERE, STATS, …)
    ESQLCommandOption           named sub-clause (e.g. BY in STATS … BY)
    ESQLAstExpression           any expression in a command argument
      ESQLFunction              function call, binary op, unary op
      ESQLColumn                column reference (@timestamp, user.name)
      ESQLLiteral               scalar literal (number, string, boolean, null)
      ESQLSource                index source reference (logs-*, cluster:index)
      ESQLList                  list literal ([1, 2, 3])
      ESQLInlineCast            inline cast (expr::type)
      ESQLParamLiteral          parameter placeholder (?, ?name, ?1)
  ESQLAstHeaderCommand          pre-query instructions (SET key = value; LET name = (subquery);)

Notes

  • ESQLAst is ESQLAstCommand[], the historic array form of a query. Prefer ESQLAstQueryExpression (which wraps the command list as a proper AST node) for new code.
  • ESQLFunction covers function calls, binary expressions (a + b, a == b), and unary expressions (-x, NOT x). Narrow with the subtype field: 'variadic-call', 'binary-expression', 'unary-expression', 'postfix-unary-expression'.
  • Location info (ESQLLocation with min/max offsets) is set during parsing and zeroed when nodes are constructed with Builder.

版本与发布记录

@elastic/esql-types 共发布 34 个版本,首次发布于 2026/07/06;过去 12 个月发布了 34 个版本。最新版本附带 npm provenance 构建来源证明,可追溯到公开的 CI 构建记录。

版本发布日期距今
4.39.0latest2026/11/112 天前
4.38.02026/11/094 天前
4.37.02026/11/058 天前
4.36.02026/11/0211 天前
4.35.02026/10/2915 天前
4.34.02026/10/2618 天前

关于 @elastic/esql-types 的常见问题

@elastic/esql-types 是什么?

TypeScript type definitions for the ES|QL AST.

如何安装 @elastic/esql-types?

在项目目录运行 npm install @elastic/esql-types,或使用 pnpm add / yarn add / bun add。

@elastic/esql-types 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

@elastic/esql-types 支持 ESM 还是 CommonJS?

同时提供 ES Module 与 CommonJS 入口,import 和 require() 都可以使用,打包工具会自动选择合适的版本。

@elastic/esql-types 可以商用吗?

@elastic/esql-types 使用 Elastic-2.0 许可。声明的许可为 Elastic-2.0,请阅读许可原文确认使用条件。以上为概括,不构成法律意见,请以许可原文为准。

@elastic/esql-types 的下载量有多少?

根据 npm 官方下载统计,@elastic/esql-types 在 2026/10/14 – 2026/11/12 这 30 天内被下载 394,486 次,日均约 13,150 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@elastic/esql-types 还在维护吗?

最新版本 4.39.0 发布于 2026/11/11(2 天前);至今共发布 34 个版本,其中过去 12 个月发布了 34 个;首次发布于 2026/07/06。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。