npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

es-eql

v1.0.2

Published

Elasticsearch Easy Query Builder

Downloads

5

Readme

es-eql

Elasticsearch Easy Query Builder

Builds simple Elasticsearch queries using standard programming syntax. Not all queries that can be expressed in Elasticsearch are possible, but those that are possible are simple to write. This can be used to expose Elasticsearch queries to a moderately technical user with little extra training.

Installation

es-eql is your typical NPM package.

npm install --save es-eql

Usage

A basic example

import * as elasticsearch from "elasticsearch";
import * as eseql from "es-eql";

const es = new elasticsearch.Client({
    apiVersion: "5.1",
    hosts: "myhostname"
});

es.search({
    index: "myindex",
    type: "mytype",
    body: eseql.buildElasticsearchQuery("environment == 'production' && (tag == 'http' || tag == 'ftp')")
}).then(result => {
    console.log("search result", result.hits.hits.map(d => d._source));
}, error => {
    console.log("search error", error);
});

Writing easy queries

The following operators are supported:

| symbol | operation | |:-------|:----------------------| | () | operation grouping | | ! | logical negation | | && | logical and | | || | logical or | | == | logical equals | | != | logical not equals | | = | wildcard match | | != | wildcard not match | | ~= | fuzzy match | | !~= | fuzzy not match | | < | less than | | <= | less than or equals | | > | greater than | | >= | greater than or equals|

All comparison operators must work against a literal value. For example threat.level > 5 and flavor == 'chocolate' are valid. flavor == color is not valid because Elasticsearch does not allow comparing values within a document.

Existence of a field can be required with the field name and no operator (JavaScript-style truthiness). Non existence of a field can be required by negating the field. eg: environment, !environment.

Field verification

buildElasticsearchQuery accepts an options param that can verify whether a field name is valid.

eg:

const options = {
    fieldVerifier: function (field) {
       switch (field) {
           case "x":
           case "z.a":
           case "z.b":
           case "z.c":
               return true;
       }
       return false;
   }
};

// valid
eseql.buildElasticsearchQuery("x == 1", options);    
eseql.buildElasticsearchQuery("z.a == 1 && z.b != -2", options);

// invalid
eseql.buildElasticsearchQuery("y == 9", options);