opensearch-project / sql-cli

The SQL CLI component in OpenSearch is a stand-alone Python application for query
Apache License 2.0
4 stars 13 forks source link
cli opensearch sql

SQL CLI Test and Build Latest Version Documentation Chat PyPi Downloads PRs welcome!

OpenSearch SQL CLI

The SQL CLI component in OpenSearch is a stand-alone Python application and can be launched by a 'wake' word opensearchsql.

It only supports OpenSearch SQL Plugin You must have the OpenSearch SQL plugin installed to your OpenSearch instance to connect. Users can run this CLI from Unix like OS or Windows, and connect to any valid OpenSearch end-point such as Amazon OpenSearch Service.

SQL CLI

Test and build SQL CLI CI

Features

Version

Unlike plugins which use 4-digit version number. SQl-CLI uses x.x.x as version number same as other python packages in OpenSearch family. As a client for OpenSearch SQL, it has independent release. SQL-CLI should be compatible to all OpenSearch SQL versions. However since the codebase is in a monorepo, so we'll cut and name sql-cli release branch and tags differently. E.g.

release branch: sql-cli-1.0
release tag: sql-cli-v1.0.0 

Install

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

To install the SQL CLI:

  1. We suggest you install and activate a python3 virtual environment to avoid changing your local environment:

    pip install virtualenv
    virtualenv venv
    cd venv
    source ./bin/activate
  2. Install the CLI:

    pip3 install opensearchsql

    The SQL CLI only works with Python 3, since Python 2 is no longer maintained since 01/01/2020. See https://pythonclock.org/

  3. To launch the CLI, run:

    opensearchsql https://localhost:9200 --username admin --password < Admin password >

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

Configure

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.

You can also configure the following connection properties:

For a list of all available configurations, see clirc.

Using the CLI

  1. Save the sample accounts test data file.

  2. Index the sample data.

    curl -H "Content-Type: application/x-ndjson" -POST https://localhost:9200/data/_bulk -u admin:< Admin password > --insecure --data-binary "@accounts.json"
  3. Run a simple SQL command in OpenSearch SQL CLI:

    SELECT * FROM accounts;

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

The CLI supports all types of query that OpenSearch SQL supports. Refer to OpenSearch SQL basic usage documentation.

Query options

Run single query from command line with options

CLI Options

Code of Conduct

This project has adopted an Open Source Code of Conduct.

Security issue notifications

If you discover a potential security issue in this project we ask that you notify AWS/Amazon Security via our vulnerability reporting page. Please do not create a public GitHub issue for security bugs you report.

Licensing

See the LICENSE file for our project's licensing. We will ask you to confirm the licensing of your contribution.

Copyright

Copyright OpenSearch Contributors. See NOTICE for details.