SQL CLI

    Install the SQL plugin to your OpenSearch instance, run the CLI using MacOS or Linux, and connect to any valid OpenSearch end-point.

    SQL CLI has the following features:

    • Multi-line input
    • Autocomplete for SQL syntax and index names
    • Syntax highlighting
    • Formatted output:
      • Field names with color
      • Enabled horizontal display (by default) and vertical display when output is too wide for your terminal, for better visualization
      • Pagination for large output
    • Works with or without security enabled
    • Supports loading configuration files
    • Supports all SQL plugin queries

    Install

    Launch your local OpenSearch instance and make sure you have the SQL plugin installed.

    To install the SQL CLI:

    1. Install the CLI:

    The SQL CLI only works with Python 3.

    1. To launch the CLI, run:

      By default, the opensearchsql command connects to http://localhost:9200.

    When you first launch the SQL CLI, a configuration file is automatically created at ~/.config/opensearchsql-cli/config (for MacOS and Linux), the configuration is auto-loaded thereafter.

    • endpoint: You do not need to specify an option. Anything that follows the launch command opensearchsql is considered as the endpoint. If you do not provide an endpoint, by default, the SQL CLI connects to http://localhost:9200.
    • : Turns on AWS sigV4 authentication to connect to an Amazon OpenSearch endpoint. Use with the AWS CLI (aws configure) to retrieve the local AWS configuration to authenticate and connect.

    For a list of all available configurations, see .

    Using the CLI

    1. Save the sample file.

    2. Index the sample data.

    3. Run a sample SQL command:

    By default, you see a maximum output of 200 rows. To show more results, add a LIMIT clause with the desired value.

    • --help: Help page for options
    • -q: Follow by a single query
    • -f: Specify JDBC or raw format output
    • : Display data vertically
    • -e: Translate SQL to DSL

    CLI options

    • -l: Query language option. Available options are sql and ppl. Default is sql
    • --clirc: Provide path for the configuration file