Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

esql

Package Overview
Dependencies
Maintainers
1
Versions
4
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

esql - npm Package Compare versions

Comparing version 0.0.2 to 0.0.3

bower.json

27

gulpfile.js

@@ -1,5 +0,10 @@

var gulp = require('gulp')
, es = require('event-stream')
, series = require('stream-series')
, $ = require('gulp-load-plugins')()
var gulp = require('gulp')
, es = require('event-stream')
, series = require('stream-series')
, $ = require('gulp-load-plugins')()
, fs = require('fs')
, source = require('vinyl-source-stream')
, buffer = require('vinyl-buffer')
, browserify = require('browserify')
, shims = require('browserify-global-shim').configure({ 'lodash': '_' })

@@ -19,6 +24,16 @@ function pipe(src, transforms, dest) {

gulp.task('default', ['test'])
gulp.task('default', ['build'])
gulp.task('build', ['test'], function () {
return pipe(
browserify('./lib/esql.js', { standalone: 'esql' }).bundle(),
[ source('esql.js'), buffer(),
gulp.dest('./browser'),
$.uglify(), $.rename('esql.min.js')
],
'./browser')
})
gulp.task('test', ['peg'], function () {
return pipe('./test/**/*.js', [$.mocha({reporter: 'spec'})])
return pipe('./test/**/*.js', [$.mocha({ reporter: 'spec' })])
})

@@ -25,0 +40,0 @@

{
"name": "esql",
"version": "0.0.2",
"description": "Friendly query language for Elasticsearch",
"version": "0.0.3",
"description": "Humane query language for Elasticsearch",
"keywords": [
"elasticsearch", "elastic", "search",
"dsl", "query", "esql"
"elasticsearch",
"elastic",
"search",
"dsl",
"query",
"esql"
],

@@ -23,2 +27,10 @@ "main": "index.js",

"homepage": "https://github.com/buunguyen/esql",
"browserify": {
"transform": [
"browserify-shim"
]
},
"browserify-shim": {
"lodash": "global:_"
},
"dependencies": {

@@ -41,4 +53,10 @@ "lodash": "^2.4.1"

"gulp-rename": "^1.2.0",
"pegjs": "^0.8.0"
"pegjs": "^0.8.0",
"browserify": "^6.1.0",
"browserify-shim": "^3.8.0",
"gulp-uglify": "^1.0.1",
"vinyl-source-stream": "^1.0.0",
"vinyl-buffer": "^1.0.0",
"vinyl-transform": "0.0.1"
}
}
### ESQL (Elasticsearch Query Language)
Elasticsearch is powerful, so is its DSL. But like most things, power comes at a cost: complexity. Even the simplest DSL queries are verbose and difficult to write. EQL is the answer.
Elasticsearch is powerful, so is its Query DSL. But Elasticsearch Query DSL's power comes at a cost: complexity. Even the simplest queries can be verbose and difficult to write. ESQL simplifies the construction of Query DSL by compiling queries written in an SQL-like language to Elasticsearch DSL. By only supporting essential features of the Query DSL, ESQL queries can be kept very simple.
ESQL compiles queries written in SQL-like syntax to Elasticsearch DSL. By only supporting common features of the Elasticsearch DSL, ESQL queries can be kept very smiple.
The output of ESQL can be used directly as the search argument of [elasticsearch-js](https://github.com/elasticsearch/elasticsearch-js). However, you may pick different portions should you use another mechanism to connect to Elasticsearch. You can also augment the output however you like. Therefore, you are not locked in to only the features supported by ESQL.
Because the output of ESQL is a full-blown Elasticsearch DSL tree, you can augment the tree however you like. For example, you can modify the tree to add behaviors not supported by ESQL. Therefore, you are not locked in to only the features supported by ESQL.
ESQL can be used in both Node and browser environments.
#### Features
* Scope: specify indices, types and options
* Filter: `term`, `terms`, `range`
* Query: `match`, `multi_match`, `range`
* Filter/query group: `must`, `should`, `must_not`
* Sort: `sort`, `asc`, `desc`
* Data types: `boolean`, `number`, `string`/`date`, `array`, `null`
* Options can be specified at each level of granularity
* Query parameterization and precompilation
* More to come...
**Note:** this is an early release of ESQL, expect the language itself and possibly the API to change. Oh yes, and bugs too. Bug reports and pull requests are very welcome.
### Getting started
Install ESQL
Install ESQL from NPM or Bower
```
npm install esql
npm install --save esql
```
Build DSL tree
```
bower install --save esql
```
Import `esql` object in Node
```javascript
var esql = require('esql')
var query = 'esql query'
var dsl = esql(query)
```
Consume DSL tree with [elasticsearch-js](https://github.com/elasticsearch/elasticsearch-js)
Import `esql` object in browser (after referencing `browser/esql.min.js`)
```javascript
var es = require('elasticsearch')
var client = new es.Client({...})
client.search(dsl).then(callback, errback)
var esql = window.esql
```
Build DSL query
```javascript
var query = 'ESQL QUERY HERE'
var dsl = esql(query)
```
Parameterize queries

@@ -40,11 +62,20 @@ ```javascript

### Example
Consume DSL query with [elasticsearch-js](https://github.com/elasticsearch/elasticsearch-js)
```javascript
var client = new es.Client({...})
client.search(dsl).then(callback, errback)
```
#### Example
```javascript
esql('from org / documents with ("from": 20, size: 10) \
filter expired == false, level == 3..5 \
match name = "foo" (boost: 2), description = "bar" with (minimum_should_match: 1)\
sort name asc, description')
var dsl = esql(
'from org / documents with ("from": 20, size: 10) \
filter expired == false, level == 3..5 \
match name = "foo" (boost: 2), description = "foo bar" (operator: "and") with (minimum_should_match: 1) \
sort name asc, description')
```
results in the following object:
The resulting `dsl` object is:
```json

@@ -88,3 +119,6 @@ {

"match": {
"description": "bar"
"description": {
"operator": "and",
"query": "foo bar"
}
}

@@ -117,17 +151,26 @@ }

The `dsl` object can be fed directly to [elasticsearch-js](https://github.com/elasticsearch/elasticsearch-js). Or you can just use its `body` property as POST data for your own Elasticsearch query mechanism.
### Syntax Reference
* ESQL is case insensitive
* All clauses are optional
* `=` is mapped to DSL `should`
* `==` is mapped to DSL `must`
* `!=` is mapped to DSL `must_not`
* Data types: boolean, number, string, arrays, null
* Range filters and queries are supported with range syntax:
* from..to => from `from` to `to` inclusively
* from...to => from `from` to `to` exclusively
* Either `from` or `to` can be optional
#### Basics
ESQL is case insensitive. Spaces and newlines are skipped so you can have as many of them. All clauses are optional although if specified, they must follow this order: `from`, `filter`, `query`, `sort`.
Filter/query groups are made possible with these mappings:
* `=` is mapped to `should`
* `==` is mapped to `must`
* `!=` is mapped to `must_not`
Range filters and queries are supported with range syntax:
* from..to => from `from` to `to` inclusively
* from...to => from `from` to `to` exclusively
* Either `from` or `to` can be optional
Options can be specified for each filter, match, sort condition or the entire group. Option names and values are not type-checked or validated in anyway whatsoever. This makes the language simple and flexible but requires you to learn about the available options.
#### FROM clause

@@ -159,3 +202,3 @@

Use the `filter` clause to create filters and filtered queries.
Use the `filter` clause to create filters.

@@ -180,3 +223,3 @@ Example 1: term search

Use the `filter` clause to create queries.
Use the `match` clause to create queries.

@@ -183,0 +226,0 @@ Example 1: single match

@@ -33,3 +33,2 @@ var expect = require('chai').expect

var res = eql('from _ with ("from": 10, size: 20)')
json(res)
expect(res.from).to.equal(10)

@@ -36,0 +35,0 @@ expect(res.size).to.equal(20)

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc