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

esq

Package Overview
Dependencies
Maintainers
1
Versions
14
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

esq

Easily build elasticsearch queries

  • 0.0.1
  • v0.0.1
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
1.3K
decreased by-4.06%
Maintainers
1
Weekly downloads
 
Created
Source

ESQ

ESQ is a helper module for elasticsearch. It aims to provide an easy way of creating elasticsearch queries.

Quick Examples

var ESQ = require('esq');

var esq = new ESQ();
var query = null;

query = esq.bool('filtered', 'query', 'bool', 'must', esq.match('foo', 'bar'));
query = esq.bool('filtered', 'query', 'bool', 'must', esq.match('date', '2014-02-01'));
query = esq.bool('filtered', 'query', 'bool', 'should', esq.range('time', '12:00', '13:00'));
query = esq.bool('filtered', 'query', 'bool', 'minimum_should_match', 1);

// query == {
//  "filtered": {
//    "query": {
//      "bool": {
//        "must": {
//          "match": {
//            "date": "2014-02-01"
//          }
//        },
//        "should": {
//          "range": {
//            "time": {
//              "gte": "12:00",
//              "lte": "13:00"
//            }
//          }
//        },
//        "minimum_should_match": 1
//      }
//    }
//  }
//}

var ESQ = require('esq');

var esq = new ESQ();

esq.query('query', esq.match('foo', 'bar'));
esq.query('query', esq.range('x', '1', '5'));
esq.query('query', esq.wildcard('test', 'what'));

var query = esq.getQuery();

// query == {
//  "query": {
//    "match": {
//      "foo": "bar"
//    },
//    "range": {
//      "x": {
//        "gte": "1",
//        "lte": "5"
//      }
//    },
//    "wildcard": {
//      "test": {
//        "value": "what"
//      }
//    }
//  }
//}

Download

npm install esq

In the Browser

Coming soon!

Documentation

Queries

esq.query(str, ..., str, value);

You can pass the function as many strings as you want and you'll receive a nested object with the arguments as keys. The final value (query component) will be assigned to the final object.

Example

esq.query('filtered', 'query', esq.match('foo', 'bar'));

Generates

{
  filtered: {
    query: {
      match: {
        foo: 'bar'
      }
    }
  }
}

esq.bool(str, ..., str, operator, value);

Same as above, however the second to last parameter must be one of the following operators: must, must_not, should or minimum_should_match. This will ensure that the final value is assigned correctly or pushed into an array.

Example

esq.bool('filtered', 'filter', 'bool', 'must', esq.term('foo', 'bar'));

Generates

{
  filtered: {
    filter: {
      bool: {
        must: [
          {
            term: { foo: 'bar' }
          }
        ]
      }
    }
  }
}

Query Components

esq.match(key, value);

Build a match query component using the key and value provided.

Example

esq.match('foo', 'bar');

Generates

{
  match: {
    foo: 'bar'
  }
}

esq.term(key, value);

Build a term query component using the key and value provided.

Example

esq.term('foo', 'bar');

Generates

{
  term: {
    foo: 'bar'
  }
}

esq.range(key, gte, lte);

Build a range query using the key, grater than equal and/or less than equal provided.

Example

esq.range('foo', 1, 5);

Generates

{
  range: {
    foo: {
      gte: 1,
      lte: 5
    }
  }
}

esq.wildcard(key, value);

Build a wildcard query component using the key and value provided.

Example

esq.wildcard('foo', 'bar*');

Generates

{
  wildcard: {
    foo: {
      value: 'bar*'
    }
  }
}

Keywords

FAQs

Package last updated on 27 Mar 2014

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

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