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

angular-elastic-builder

v1.5.1

Published

Angular Module for building an Elasticsearch Query

Downloads

24

Readme

Angular Elasticsearch Query Builder

NPM version Bower version Downloads Tips

This is an Angular.js directive for building an Elasticsearch query. You just give it the fields and can generate a query for it. Its layout is defined using Bootstrap classes, but you may also choose to just style it yourself.

It's still pretty early on, as it doesn't support a whole lot of use-cases, but we need to make it awesome. Contributions accepted.

Try it Out

View an example here

Usage

Dependency

Notice: this plugin requires:

Installation

First you'll need to download the dist files and include this JS file to your app (don't forget to substitute x.x.x with the current version number), along with the RecursionHelper, if you're not already using it.

<script type="text/javascript" src="angular-ui-bootstrap/ui-bootstrap-tpls.js"></script>
<script type="text/javascript" src="angular-recursion/angular-recursion.min.js"></script>
<script type="text/javascript" src="angular-elastic-builder/angular-elastic-builder.min.js"></script>

Then make sure that it's included in your app's dependencies during module creation.

angularmodule('appName', [ 'angular-elastic-builder' ]);

Then you can use it in your app

/* Controller code */

/**
 * The elasticBuilderData object will be modified in place so that you can use
 * your own $watch, and/or your own saving mechanism
 */
$scope.elasticBuilderData = {};
$scope.elasticBuilderData.query = [];

/**
 * This object is the lookup for what fields
 * are available in your database, as well as definitions of what kind
 * of data they are
 */
$scope.elasticBuilderData.fields = {
 'test.number': { type: 'number', minimum: 650 },
 'test.term': { type: 'term' },
 'test.boolean': { type: 'term', subType: 'boolean' },
 'test.state.multi': { type: 'multi', choices: [ 'AZ', 'CA', 'CT' ]},
 'test.date': { type: 'date' },
 'test.otherdate': { type: 'date' }
};
<div data-elastic-builder="elasticBuilderData"></div>

The above elasticFields would allow you create the following form: Screenshot

Which represents the following Elasticsearch Query:

[
  {
    "and": [
      {
        "term": {
          "test.date": "2016-04-08T10:44:06"
        }
      },
      {
        "range": {
          "test.number": {
            "gte": 650
          }
        }
      },
      {
        "range": {
          "test.number": {
            "lt": 850
          }
        }
      }
    ]
  },
  {
    "term": {
      "test.boolean": 0
    }
  },
  {
    "terms": {
      "test.state.multi": [ "AZ", "CT" ]
    }
  },
  {
    "not": {
      "filter": {
        "term": {
          "test.term": "asdfasdf"
        }
      }
    }
  },
  {
    "exists": {
      "field": "test.term"
    }
  },
  {
    "range": {
      "test.otherdate": {
        "gte": "now",
        "lte": "now+7d"
      }
    }
  }
]

Field Options

  • type: This determines how the fields are displayed in the form.
    • Currently supported:
      • 'number': in addition to Generic Options, gets ">", "≥", "<", "≤", "="
      • 'term': in addition to Generic Options, gets "Equals" and "! Equals"
      • 'boolean': Does not get Generic Options. Gets true and false
        • These are actually "equals 0" and "equals 1" for the database query
      • 'date': in addition to Generic Options, gets ">", "≥", "<", "≤", "="

Generic Options

  • In addition to any specific options for fields, all fields also get a "Exists" and "! Exists" option

External Changes && Initial State

If you want to pass in an initial state (or if you make changes to the query externally), you'll need to set the configuration flag needsUpdate to true. Any time this flag changes to true, this directive will overwrite the current state and data with whatever is now defined in your configuration object.

Local Development

To work on this module locally, you will need to clone it and run gulp watch. This will ensure that your changes get compiled properly. You will also need to make sure you run gulp to build the "dist" files before commit.