Skip to content

Latest commit

 

History

History
70 lines (54 loc) · 2.8 KB

File metadata and controls

70 lines (54 loc) · 2.8 KB

Mutation API

The ES|QL mutation API provides methods to navigate and modify the AST.

Usage

For example, insert a FROM command METADATA field:

import { parse, mutate, BasicPrettyPrinter } from '@elastic/esql';

const { root } = parse('FROM index METADATA _lang');

console.log([...mutate.commands.from.metadata.list(root)]); // [ '_lang' ]

mutate.commands.from.metadata.upsert(root, '_id');

console.log([...mutate.commands.from.metadata.list(root)]); // [ '_lang', '_id' ]

const src = BasicPrettyPrinter.print(root);

console.log(src); // FROM index METADATA _lang, _id

API

  • .generic
    • .listCommands() — Lists all commands. Returns an iterator.
    • .findCommand() — Finds a specific command by a predicate function.
    • .findCommandOption() — Finds a specific command option by a predicate function.
    • .findCommandByName() — Finds a specific command by name.
    • .findCommandOptionByName() — Finds a specific command option by name.
    • .appendCommand() — Add a new command to the AST.
    • .appendCommandOption() — Add a new command option to a command.
    • .appendCommandArgument() — Add a new main command argument to a command.
    • .removeCommand() — Remove a command from the AST.
    • .removeCommandOption() — Remove a command option from the AST.
    • .removeCommandArgument() — Remove a command argument from the AST.
  • .commands
    • .from
      • .sources
        • .list() — List all FROM sources.
        • .find() — Find a source by name.
        • .remove() — Remove a source by name.
        • .insert() — Insert a source.
        • .upsert() — Insert a source, if it does not exist.
      • .metadata
        • .list() — List all METADATA fields.
        • .find() — Find a METADATA field by name.
        • .removeByPredicate() — Remove a METADATA field by matching a predicate function.
        • .remove() — Remove a METADATA field by name.
        • .insert() — Insert a METADATA field.
        • .upsert() — Insert METADATA field, if it does not exist.
    • .limit
      • .list() — List all LIMIT commands.
      • .byIndex() — Find a LIMIT command by index.
      • .find() — Find a LIMIT command by a predicate function.
      • .remove() — Remove a LIMIT command by index.
      • .set() — Set the limit value of a specific LIMIT command.
      • .upsert() — Insert a LIMIT command, or update the limit value if it already exists.
    • .stats
      • .list() — List all STATS commands.
      • .byIndex() — Find a STATS command by index.
    • .join
      • .list() — List all JOIN commands.
      • .byIndex() — Find a JOIN command by index.