• This repository has been archived on 02/Aug/2022
  • Stars
    star
    620
  • Rank 72,387 (Top 2 %)
  • Language
    Java
  • License
    Apache License 2.0
  • Created almost 6 years ago
  • Updated over 2 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

🔍 Open Distro SQL Plugin

Test and Build Workflow codecov Documentation Chat PRs welcome!

Open Distro for Elasticsearch SQL

Open Distro for Elasticsearch enables you to extract insights out of Elasticsearch using the familiar SQL query syntax. Use aggregations, group by, and where clauses to investigate your data. Read your data as JSON documents or CSV tables so you have the flexibility to use the format that works best for you.

SQL Related Projects

The following projects have been merged into this repository as separate folders as of July 9, 2020. Please refer to links below for details. This document will focus on the SQL plugin for Elasticsearch.

Documentation

Please refer to the SQL Language Reference Manual, Piped Processing Language (PPL) Reference Manual and Technical Documentation for detailed information on installing and configuring opendistro-elasticsearch-sql plugin. Looking to contribute? Read the instructions on Development Guide and then submit a patch!

SQL Engine V2

Recently we have been actively improving our query engine primarily for better correctness and extensibility. Behind the scene, the new enhanced engine has already supported the new released Piped Processing Language. However, it was experimental and disabled by default for SQL query processing. With most important features and full testing complete, now we're ready to promote it as our default SQL query engine. Please find more details in SQL Engine V2 - Release Notes.

Setup

Install as plugin: build plugin from source code by following the instruction in Build section and install it to your Elasticsearch.

After doing this, you need to restart the Elasticsearch server. Otherwise you may get errors like Invalid index name [sql], must not start with '']; ","status":400}.

Build

The package uses the Gradle build system.

  1. Checkout this package from version control.
  2. To build from command line set JAVA_HOME to point to a JDK >=14
  3. Run ./gradlew build

Basic Usage

To use the feature, send requests to the _opendistro/_sql URI. You can use a request parameter or the request body (recommended).

  • Simple query
POST https://<host>:<port>/_opendistro/_sql
{
  "query": "SELECT * FROM my-index LIMIT 50"
}
  • Explain SQL to elasticsearch query DSL
POST _opendistro/_sql/_explain
{
  "query": "SELECT * FROM my-index LIMIT 50"
}
  • For a sample curl command with the Open Distro for Elasticsearch Security plugin, try:
curl -XPOST https://localhost:9200/_opendistro/_sql -u admin:admin -k -d '{"query": "SELECT * FROM my-index LIMIT 10"}' -H 'Content-Type: application/json'

SQL Usage

  • Query

      SELECT * FROM bank WHERE age >30 AND gender = 'm'
    
  • Aggregation

      SELECT COUNT(*),SUM(age),MIN(age) as m, MAX(age),AVG(age)
      FROM bank
      GROUP BY gender
      HAVING m >= 20
      ORDER BY SUM(age), m DESC
    
  • Join

      SELECT b1.firstname, b1.lastname, b2.age
      FROM bank b1
      LEFT JOIN bank b2
      ON b1.age = b2.age AND b1.state = b2.state
    
  • Show

      SHOW TABLES LIKE ban%
      DESCRIBE TABLES LIKE bank
    
  • Delete

      DELETE FROM bank WHERE age >30 AND gender = 'm'
    

Beyond SQL

  • Search

      SELECT address FROM bank WHERE address = matchQuery('880 Holmes Lane') ORDER BY _score DESC LIMIT 3
    
  • Nested Field

    •   SELECT address FROM bank b, b.nestedField e WHERE b.state = 'WA' and e.name = 'test'
      
    •   SELECT address, nested(nestedField.name)
        FROM bank
        WHERE nested(nestedField, nestedField.state = 'WA' AND nestedField.name = 'test')
           OR nested(nestedField.state) = 'CA'
      
  • Aggregations

    • range age group 20-25,25-30,30-35,35-40

        SELECT COUNT(age) FROM bank GROUP BY range(age, 20,25,30,35,40)
      
    • range date group by day

        SELECT online FROM online GROUP BY date_histogram(field='insert_time','interval'='1d')
      
    • range date group by your config

        SELECT online FROM online GROUP BY date_range(field='insert_time','format'='yyyy-MM-dd' ,'2014-08-18','2014-08-17','now-8d','now-7d','now-6d','now')
      
  • ES Geographic

      SELECT * FROM locations WHERE GEO_BOUNDING_BOX(fieldname,100.0,1.0,101,0.0)
    
  • Select type or pattern

      SELECT * FROM indexName/type
      SELECT * FROM index*
    

SQL Features

  • SQL Select
  • SQL Delete
  • SQL Where
  • SQL Order By
  • SQL Group By
  • SQL Having
  • SQL Inner Join
  • SQL Left Join
  • SQL Show
  • SQL Describe
  • SQL AND & OR
  • SQL Like
  • SQL COUNT distinct
  • SQL In
  • SQL Between
  • SQL Aliases
  • SQL Not Null
  • SQL(ES) Date
  • SQL avg()
  • SQL count()
  • SQL max()
  • SQL min()
  • SQL sum()
  • SQL Nulls
  • SQL isnull()
  • SQL floor
  • SQL trim
  • SQL log
  • SQL log10
  • SQL substring
  • SQL round
  • SQL sqrt
  • SQL concat_ws
  • SQL union and minus

JDBC Support

Please check out JDBC driver repository for more details.

Beyond sql features

  • ES TopHits
  • ES MISSING
  • ES STATS
  • ES GEO_INTERSECTS
  • ES GEO_BOUNDING_BOX
  • ES GEO_DISTANCE
  • ES GEOHASH_GRID aggregation

Attribution

This project is based on the Apache 2.0-licensed elasticsearch-sql project. Thank you eliranmoyal, shi-yuan, ansjsun and everyone else who contributed great code to that project. Read this for more details Attributions.

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.

Licensing

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

Copyright

Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved.

More Repositories

1

opendistro-build

🧰 Open Distro Build Scripts
Shell
343
star
2

alerting

📟 Open Distro Alerting Plugin
Kotlin
279
star
3

sample-code

👋 Welcome to the Open Distro sample-code area. Share your great ideas and code samples with the Open Distro Community.
Python
278
star
4

k-NN

🆕 A machine learning plugin which supports an approximate k-NN search algorithm for Open Distro.
Java
276
star
5

performance-analyzer

📈 OpenDistro Performance Analyzer
Java
146
star
6

alerting-kibana-plugin

📟 Open Distro Kibana Alerting Plugin
JavaScript
140
star
7

index-management

🗃 Open Distro Index Management
Kotlin
115
star
8

perftop

📈 PerfTop: A client for the Open Distro Performance Analyzer
JavaScript
94
star
9

anomaly-detection

A machine learning plugin in Open Distro for real time anomaly detection on streaming data.
Java
78
star
10

job-scheduler

🕓 Open Distro Job Scheduler
Java
47
star
11

deprecated-security-advanced-modules

[DO NOT USE - DEPRECATED as of v1.4.0] Advanced modules for the Open Distro security plugin; Merged into security repo.
Java
47
star
12

anomaly-detection-kibana-plugin

A Kibana plugin providing visualizations for anomaly detection in Open Distro.
TypeScript
44
star
13

index-management-kibana-plugin

🗃 Open Distro Index Management Kibana UI plugin
TypeScript
42
star
14

kibana-reports

Kibana Reports
TypeScript
39
star
15

performance-analyzer-rca

The Performance Analyzer RCA is a framework that builds on the Performance Analyzer engine to support root cause analysis (RCA) of performance and reliability problems for Elasticsearch instances.
Java
38
star
16

data-prepper

This repository is archived. Please migrate to the active project: https://github.com/opensearch-project/data-prepper
Java
37
star
17

deprecated-security-ssl

[DO NOT USE - DEPRECATED AS OF v1.0.0] SSL module for Open Distro security plugin
Java
31
star
18

odfe-cli

A full-featured command line interface (CLI) for Open Distro.
Go
24
star
19

asynchronous-search

▶️ Asynchronous search makes it possible for users to run queries in the background, allowing users to track the progress, and retrieve partial results as they become available.
Java
23
star
20

kibana-notebooks

Open Distro Kibana Notebooks
TypeScript
21
star
21

deprecated-security-parent

[DO NOT USE - DEPRECATED as of v1.4.0] Parent repo for Open Distro Security plugin; Merged into security repo.
19
star
22

security

Java
17
star
23

cross-cluster-replication

Kotlin
15
star
24

trace-analytics

TypeScript
7
star
25

kibana-visualizations

TypeScript
4
star
26

common-utils

Open Distro Common-Utils
Java
4
star
27

security-kibana-plugin

TypeScript
3
star
28

notifications

Notifications plugin for Open Distro enables other plugins to send notifications via Email, Slack, Amazon Chime, Custom web-hook etc channels
Kotlin
3
star
29

pipe-processing-language

Piped Processing Language (PPL) for Elasticsearch
3
star