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

esq

Package Overview
Dependencies
Maintainers
2
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

  • 1.0.0
  • latest
  • Source
  • npm
  • Socket score

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

ESQ (Elasticsearch Query)

Build Status

I wanted an easy way to build elasticsearch queries without having to writing lots and lots of code just for the structure of the query. For that reason I created ESQ, a very simple but powerful tool that will do all of the object creation for you.


Download

npm install esq or bower intall esq


Quick Example

Example

var ESQ = require('esq');
var esq = new ESQ();

esq.query('bool', ['must'], { match: { user: 'kimchy' } });
esq.query('bool', 'minimum_should_match', 1);

var query = esq.getQuery();

Generates

{
  "bool": {
    "must": [
      {
        "match": {
          "user": "kimchy"
        }
      }
    ],
    "minimum_should_match": 1
  }
}

In the browser

<script src="esq.js"></script>
<script>
  var esq = new ESQ();
  esq.query('bool', ['must'], { match: { user: 'kimchy' } });
  var query = esq.getQuery();
</script>

Documentation

esq.getQuery();

This will return the query at the current stage.

Example

esq.query('bool', ['must'], { match: { foo: 'bar' } });
var query = esq.getQuery();

Generates

{
  "bool": {
    "must": [
      {
        "match": {
          "foo": "bar"
        }
      }
    ]
  }
}

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

You can pass this function as many strings as you want and you'll receive a nested object with the arguments as keys. The final argument should always be the object you want to assign to the second to last argument. This function will always return the query at its current state.

Example

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

Generates

{
  "filtered": {
    "query": {
      "match": {
        "foo": "bar"
      }
    }
  }
}
Array Arguments

The function also allows you to pass in an argument as an array (e.g. ['must']). This tells the function that you want that key to be an array and so it'll push the following arguments into the array.

Example

esq.query('filtered', 'query', 'bool', ['must'], { match: { 'foo': 'bar' } });

Generates

{
  "filtered": {
    "query": {
      "bool": {
        "must": [
          {
            "match": {
              "foo": "bar"
            }
          }
        ]
      }
    }
  }
}

Tests

This module is fully tested, run the tests using mocha.

Keywords

FAQs

Package last updated on 25 Jan 2016

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